diff --git a/include/wx/x11/app.h b/include/wx/x11/app.h index 1ae32973b4..c0adc4bfb5 100644 --- a/include/wx/x11/app.h +++ b/include/wx/x11/app.h @@ -41,8 +41,6 @@ public: // override base class (pure) virtuals // ----------------------------------- - virtual void Exit(); - virtual void WakeUpIdle(); virtual bool OnInitGui(); diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 8574d4fe8e..875e412e56 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -149,6 +149,22 @@ void wxAppBase::CleanUp() // and any remaining TLWs DeleteAllTLWs(); +#if wxUSE_LOG + // flush the logged messages if any and don't use the current probably + // unsafe log target any more: the default one (wxLogGui) can't be used + // after the resources are freed below and the user supplied one might be + // even worse (using any wxWidgets GUI function is unsafe starting from + // now) + // + // notice that wxLog will still recreate a default log target if any + // messages are logged but that one will be safe to use until the very end + delete wxLog::SetActiveTarget(nullptr); +#endif // wxUSE_LOG + + // Starting from now, the application object is no longer valid and + // shouldn't be used any longer, so reset the global pointer to it. + wxApp::SetInstance(nullptr); + // undo everything we did in Initialize() above wxBitmap::CleanUpHandlers(); diff --git a/src/common/init.cpp b/src/common/init.cpp index d186cfb913..39cb90b41b 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -440,22 +440,6 @@ bool wxEntryStart(int& argc, char **argv) // clean up // ---------------------------------------------------------------------------- -// cleanup done before destroying wxTheApp -static void DoCommonPreCleanup() -{ -#if wxUSE_LOG - // flush the logged messages if any and don't use the current probably - // unsafe log target any more: the default one (wxLogGui) can't be used - // after the resources are freed which happens when we return and the user - // supplied one might be even more unsafe (using any wxWidgets GUI function - // is unsafe starting from now) - // - // notice that wxLog will still recreate a default log target if any - // messages are logged but that one will be safe to use until the very end - delete wxLog::SetActiveTarget(nullptr); -#endif // wxUSE_LOG -} - // cleanup done after destroying wxTheApp static void DoCommonPostCleanup() { @@ -488,20 +472,18 @@ static void DoCommonPostCleanup() void wxEntryCleanup() { - DoCommonPreCleanup(); - - // delete the application object - if ( wxTheApp ) + if ( wxAppConsole * const app = wxApp::GetInstance() ) { + app->CleanUp(); + // reset the global pointer to it to nullptr before destroying it as in // some circumstances this can result in executing the code using - // wxTheApp and using half-destroyed object is no good - wxAppConsole * const app = wxApp::GetInstance(); + // wxTheApp and using half-destroyed object is no good (note that it + // usually would be already reset by wxAppBase::CleanUp(), but ensure + // that it is definitely done by doing it here too) wxApp::SetInstance(nullptr); - app->CleanUp(); - delete app; } diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index f5e111e519..d03300d7f0 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -5605,7 +5605,10 @@ wxDataViewCtrl::~wxDataViewCtrl() #if wxUSE_ACCESSIBILITY SetAccessible(nullptr); - wxAccessible::NotifyEvent(wxACC_EVENT_OBJECT_DESTROY, this, wxOBJID_CLIENT, wxACC_SELF); + // There is no need to notify anybody if we're destroyed as part of + // application shutdown and doing it would just crash in this case. + if ( wxTheApp ) + wxAccessible::NotifyEvent(wxACC_EVENT_OBJECT_DESTROY, this, wxOBJID_CLIENT, wxACC_SELF); #endif // wxUSE_ACCESSIBILITY } diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 8537b4f8cf..b8604051f5 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -568,6 +568,8 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) void wxApp::CleanUp() { + wxAppBase::CleanUp(); + if (m_idleSourceId != 0) g_source_remove(m_idleSourceId); @@ -577,8 +579,6 @@ void wxApp::CleanUp() g_type_class_unref(gt); gdk_threads_leave(); - - wxAppBase::CleanUp(); } void wxApp::WakeUpIdle() diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index eba9652e47..0683e8dc40 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -358,13 +358,14 @@ int wxApp::OnRun() void wxApp::CleanUp() { wxMacAutoreleasePool autoreleasepool; + + wxAppBase::CleanUp(); + #if wxUSE_TOOLTIPS wxToolTip::RemoveToolTips() ; #endif DoCleanUp(); - - wxAppBase::CleanUp(); } //---------------------------------------------------------------------- diff --git a/src/x11/app.cpp b/src/x11/app.cpp index ae631b283d..9da804569e 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -198,10 +198,10 @@ bool wxApp::Initialize(int& argC, wxChar **argV) void wxApp::CleanUp() { + wxAppBase::CleanUp(); + wxDELETE(wxWidgetHashTable); wxDELETE(wxClientWidgetHashTable); - - wxAppBase::CleanUp(); } wxApp::wxApp() @@ -789,11 +789,3 @@ Window wxGetWindowParent(Window window) return (Window) 0; #endif } - -void wxApp::Exit() -{ - wxApp::CleanUp(); - - wxAppConsole::Exit(); -} -