diff --git a/src/engine/platform/platform.cc b/src/engine/platform/platform.cc index 5357225..7333d29 100644 --- a/src/engine/platform/platform.cc +++ b/src/engine/platform/platform.cc @@ -16,8 +16,6 @@ using namespace base; namespace eng { -Platform::InternalError Platform::internal_error; - Platform::Platform() = default; Platform::~Platform() = default; @@ -33,10 +31,8 @@ void Platform::InitializeCommon() { #elif defined(__linux__) audio_driver_ = std::make_unique(); #endif - if (!audio_driver_->Initialize()) { - LOG << "Failed to initialize audio driver."; - throw internal_error; - } + bool res = audio_driver_->Initialize(); + CHECK(res) << "Failed to initialize audio driver."; auto context = std::make_unique(); if (context->Initialize()) { @@ -57,10 +53,8 @@ void Platform::ShutdownCommon() { void Platform::RunMainLoop() { engine_ = std::make_unique(this, renderer_.get(), audio_driver_.get()); - if (!engine_->Initialize()) { - LOG << "Failed to initialize the engine."; - throw internal_error; - } + bool res = engine_->Initialize(); + CHECK(res) << "Failed to initialize the engine."; // Use fixed time steps. float time_step = engine_->time_step(); diff --git a/src/engine/platform/platform.h b/src/engine/platform/platform.h index fe48ab8..d65169f 100644 --- a/src/engine/platform/platform.h +++ b/src/engine/platform/platform.h @@ -1,7 +1,6 @@ #ifndef ENGINE_PLATFORM_PLATFORM_H #define ENGINE_PLATFORM_PLATFORM_H -#include #include #include @@ -66,9 +65,6 @@ class Platform { bool mobile_device() const { return mobile_device_; } - static class InternalError : public std::exception { - } internal_error; - protected: base::Timer timer_; diff --git a/src/engine/platform/platform_android.cc b/src/engine/platform/platform_android.cc index 89e174f..ff9a551 100644 --- a/src/engine/platform/platform_android.cc +++ b/src/engine/platform/platform_android.cc @@ -295,10 +295,9 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) { DLOG << "APP_CMD_INIT_WINDOW"; if (app->window != NULL) { platform->SetFrameRate(60); - if (!platform->renderer_->Initialize(app->window)) { - LOG << "Failed to initialize the renderer."; - throw internal_error; - } + bool res = platform->renderer_->Initialize(app->window); + CHECK(res) << "Failed to initialize " + << platform->renderer_->GetDebugName() << " renderer."; } break; @@ -315,10 +314,9 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) { if (width != ANativeWindow_getWidth(app->window) || height != ANativeWindow_getHeight(app->window)) { platform->renderer_->Shutdown(); - if (!platform->renderer_->Initialize(platform->app_->window)) { - LOG << "Failed to initialize the renderer."; - throw internal_error; - } + bool res = platform->renderer_->Initialize(platform->app_->window); + CHECK(res) << "Failed to initialize " + << platform->renderer_->GetDebugName() << " renderer."; } } break; @@ -445,11 +443,8 @@ void Platform::SetFrameRate(float frame_rate) { void android_main(android_app* app) { eng::Platform platform; - try { - platform.Initialize(app); - platform.RunMainLoop(); - platform.Shutdown(); - } catch (eng::Platform::InternalError& e) { - } + platform.Initialize(app); + platform.RunMainLoop(); + platform.Shutdown(); _exit(0); } diff --git a/src/engine/platform/platform_linux.cc b/src/engine/platform/platform_linux.cc index 1ab0eb7..b3fc648 100644 --- a/src/engine/platform/platform_linux.cc +++ b/src/engine/platform/platform_linux.cc @@ -23,15 +23,12 @@ void Platform::Initialize() { shared_data_path_ = "./"; LOG << "Shared data path: " << shared_data_path_.c_str(); - if (!CreateWindow(800, 1205)) { - LOG << "Failed to create window."; - throw internal_error; - } + bool res = CreateWindow(800, 1205); + CHECK(res) << "Failed to create window."; - if (!renderer_->Initialize(display_, window_)) { - LOG << "Failed to initialize renderer."; - throw internal_error; - } + res = renderer_->Initialize(display_, window_); + CHECK(res) << "Failed to initialize " << renderer_->GetDebugName() + << " renderer."; XSelectInput(display_, window_, KeyPressMask | Button1MotionMask | ButtonPressMask | @@ -164,12 +161,8 @@ void Platform::DestroyWindow() { int main(int argc, char** argv) { eng::Platform platform; - try { - platform.Initialize(); - platform.RunMainLoop(); - platform.Shutdown(); - } catch (eng::Platform::InternalError& e) { - return -1; - } + platform.Initialize(); + platform.RunMainLoop(); + platform.Shutdown(); return 0; }