From 0f5501ad79950e9658fb672ac6b97a608e3a2dd9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 5 Oct 2013 15:15:07 +0300 Subject: [PATCH] Better method of preventing duplicate applications Application::run can now be called multiple times, but not recursively. --- source/core/application.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/source/core/application.cpp b/source/core/application.cpp index 43bb023..d5745ed 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -16,21 +16,16 @@ void *Application::data_ = 0; Application::Application(): exit_code(0) -{ } +{ + if(app_) + throw logic_error("instance already exists"); +} int Application::run(int argc, char **argv, void *data) { - static bool called = false; - if(called) - { - IO::cerr.write("Trying to call Application::run_app twice!\n"); - return 125; - } - called = true; - if(!starter_) { - IO::cerr.write("Trying to run with no RegisteredApplication class!\n"); + IO::cerr.write("Application::run called with no RegisteredApplication class!\n"); return 126; } @@ -68,6 +63,7 @@ int Application::run(int argc, char **argv, void *data) } delete app_; + app_ = 0; return 124; } -- 2.45.2