diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 1a8ba46e..98921da9 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -42,7 +42,6 @@ Application::Application() Application::~Application() { - this->Destroy(); } void Application::Run(RunnerPtr runner) @@ -62,6 +61,25 @@ void Application::Run(RunnerPtr runner) c->SetupModule(); } + // Ensure resources are destroyed before exiting + class DestroyHelper + { + Function f; + + public: + DestroyHelper(Function f) + : f(f) + { + } + + ~DestroyHelper() + { + f(); + } + }; + + DestroyHelper helper([=]() { this->Destroy(); }); + // Everything is ready runner->OnReady(); @@ -77,8 +95,6 @@ void Application::Run(RunnerPtr runner) if (!runner->MainLoop(timer_->GetDeltaTime())) running_ = false; } - - this->Destroy(); } void Application::Pause()