X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0471d4865048eb56cea8aabbb0ff7cbd2a95a556..c099c54cbaa285c452468419f2021899553ff9b3:/src/mgl/app.cpp?ds=sidebyside diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index 9e38dd0ef5..97786a24ba 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -7,10 +7,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "app.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -21,8 +17,6 @@ #ifndef WX_PRECOMP #include "wx/settings.h" - #include "wx/module.h" - #include "wx/evtloop.h" #include "wx/frame.h" #include "wx/dialog.h" #include "wx/log.h" @@ -30,6 +24,8 @@ #endif #include "wx/app.h" +#include "wx/evtloop.h" +#include "wx/module.h" #include "wx/fontutil.h" #include "wx/univ/theme.h" #include "wx/univ/renderer.h" @@ -280,19 +276,22 @@ bool wxApp::Initialize(int& argc, wxChar **argv) wxSetEnv(wxT("LFN"), wxT("N")); #endif + // intialize MGL before creating wxFontsManager since it uses MGL funcs + if ( MGL_init(".", NULL) == 0 ) + { + wxLogError(_("Cannot initialize SciTech MGL!")); + return false; + } + // must do it before calling wxAppBase::Initialize(), because fonts are // needed by stock lists which are created there wxTheFontsManager = new wxFontsManager; if ( !wxAppBase::Initialize(argc, argv) ) - return false; - - if ( MGL_init(".", NULL) == 0 ) { - wxLogError(_("Cannot initialize SciTech MGL!")); - - wxAppBase::CleanUp(); - + delete wxTheFontsManager; + wxTheFontsManager = NULL; + MGL_exit(); return false; } @@ -303,17 +302,31 @@ bool wxApp::Initialize(int& argc, wxChar **argv) return true; } +// Modules are cleaned up after wxApp::CleanUp(), and some modules may +// require MGL to still be alive, e.g. the stock fonts need the fonts +// manager. So append this module last minute in wxApp::CleanUp() to close +// down MGL after all the other modules have been cleaned up. +// +struct wxMGLFinalCleanup: public wxModule +{ + bool OnInit() { return true; } + + void OnExit() + { + delete wxTheFontsManager; + wxTheFontsManager = (wxFontsManager*) NULL; + + wxDestroyMGL_WM(); + MGL_exit(); + } +}; + void wxApp::CleanUp() { delete gs_rootWindow; wxAppBase::CleanUp(); - // must do this after calling base class CleanUp() - delete wxTheFontsManager; - wxTheFontsManager = (wxFontsManager*) NULL; - - wxDestroyMGL_WM(); - MGL_exit(); + wxModule::RegisterModule(new wxMGLFinalCleanup); }