X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fapplication.cpp;h=139f94f2d88054d745ad9119b562dd7ec174d596;hb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd;hp=a588e9dbb7900cff2b3d15a200f41a9be2382d8f;hpb=1876f64c4ec1bcba8de57b8b5f63e250187b4ad1;p=libs%2Fcore.git diff --git a/source/core/application.cpp b/source/core/application.cpp index a588e9d..139f94f 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -19,6 +19,10 @@ using namespace std; namespace Msp { +Application *Application::app_ = 0; +Application::Starter *Application::starter_ = 0; +void *Application::data_ = 0; + Application::Application(): exit_code(0) { } @@ -32,13 +36,13 @@ the library normally does it automatically at program startup. */ int Application::run(int argc, char **argv, void *data) { - static bool called=false; + static bool called = false; if(called) { cerr<<"Trying to call Application::run_app twice!\n"; return 125; } - called=true; + called = true; if(!starter_) { @@ -46,13 +50,13 @@ int Application::run(int argc, char **argv, void *data) return 126; } - data_=data; + data_ = data; try { try { - app_=starter_->create_app(argc, argv); + app_ = starter_->create_app(argc, argv); } catch(const UsageError &e) { @@ -60,8 +64,10 @@ int Application::run(int argc, char **argv, void *data) return 1; } - int result=app_->main(); - delete app_; + int result = app_->main(); + Application *a = app_; + app_ = 0; + delete a; return result; } catch(const exception &e) @@ -69,18 +75,18 @@ int Application::run(int argc, char **argv, void *data) delete app_; #ifdef WIN32 - string msg=Debug::demangle(typeid(e).name())+":\n"+e.what(); + string msg = Debug::demangle(typeid(e).name())+":\n"+e.what(); MessageBoxA(0, msg.c_str(), "Uncaught exception", MB_OK|MB_ICONERROR); #else cerr<<"An uncaught exception occurred.\n"; cerr<<" type: "<(&e); + const Exception *exc = dynamic_cast(&e); if(exc && !exc->get_backtrace().get_frames().empty()) { cerr<<" backtrace:\n"; - const list &frames=exc->get_backtrace().get_frames(); + const list &frames = exc->get_backtrace().get_frames(); for(list::const_iterator i=frames.begin(); i!=frames.end(); ++i) cerr<<" "<<*i<<'\n'; } @@ -149,11 +155,7 @@ Application::Starter::Starter() if(starter_) throw InvalidState("Can't create more than one Starter instance"); - starter_=this; + starter_ = this; } -Application *Application::app_=0; -Application::RegBase *Application::reg_app_=0; -void *Application::data_=0; - } // namespace Msp