Merge branch 'really-fix-cleanup'

Really fix logging during app cleanup.

See #24272.
This commit is contained in:
Vadim Zeitlin 2024-02-03 21:53:24 +01:00
commit e20a994b1f
7 changed files with 33 additions and 41 deletions

View file

@ -41,8 +41,6 @@ public:
// override base class (pure) virtuals // override base class (pure) virtuals
// ----------------------------------- // -----------------------------------
virtual void Exit();
virtual void WakeUpIdle(); virtual void WakeUpIdle();
virtual bool OnInitGui(); virtual bool OnInitGui();

View file

@ -149,6 +149,22 @@ void wxAppBase::CleanUp()
// and any remaining TLWs // and any remaining TLWs
DeleteAllTLWs(); 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 // undo everything we did in Initialize() above
wxBitmap::CleanUpHandlers(); wxBitmap::CleanUpHandlers();

View file

@ -440,22 +440,6 @@ bool wxEntryStart(int& argc, char **argv)
// clean up // 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 // cleanup done after destroying wxTheApp
static void DoCommonPostCleanup() static void DoCommonPostCleanup()
{ {
@ -488,20 +472,18 @@ static void DoCommonPostCleanup()
void wxEntryCleanup() void wxEntryCleanup()
{ {
DoCommonPreCleanup();
// delete the application object // 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 // reset the global pointer to it to nullptr before destroying it as in
// some circumstances this can result in executing the code using // some circumstances this can result in executing the code using
// wxTheApp and using half-destroyed object is no good // wxTheApp and using half-destroyed object is no good (note that it
wxAppConsole * const app = wxApp::GetInstance(); // usually would be already reset by wxAppBase::CleanUp(), but ensure
// that it is definitely done by doing it here too)
wxApp::SetInstance(nullptr); wxApp::SetInstance(nullptr);
app->CleanUp();
delete app; delete app;
} }

View file

@ -5605,7 +5605,10 @@ wxDataViewCtrl::~wxDataViewCtrl()
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
SetAccessible(nullptr); 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 #endif // wxUSE_ACCESSIBILITY
} }

View file

@ -568,6 +568,8 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_)
void wxApp::CleanUp() void wxApp::CleanUp()
{ {
wxAppBase::CleanUp();
if (m_idleSourceId != 0) if (m_idleSourceId != 0)
g_source_remove(m_idleSourceId); g_source_remove(m_idleSourceId);
@ -577,8 +579,6 @@ void wxApp::CleanUp()
g_type_class_unref(gt); g_type_class_unref(gt);
gdk_threads_leave(); gdk_threads_leave();
wxAppBase::CleanUp();
} }
void wxApp::WakeUpIdle() void wxApp::WakeUpIdle()

View file

@ -358,13 +358,14 @@ int wxApp::OnRun()
void wxApp::CleanUp() void wxApp::CleanUp()
{ {
wxMacAutoreleasePool autoreleasepool; wxMacAutoreleasePool autoreleasepool;
wxAppBase::CleanUp();
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
wxToolTip::RemoveToolTips() ; wxToolTip::RemoveToolTips() ;
#endif #endif
DoCleanUp(); DoCleanUp();
wxAppBase::CleanUp();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View file

@ -198,10 +198,10 @@ bool wxApp::Initialize(int& argC, wxChar **argV)
void wxApp::CleanUp() void wxApp::CleanUp()
{ {
wxAppBase::CleanUp();
wxDELETE(wxWidgetHashTable); wxDELETE(wxWidgetHashTable);
wxDELETE(wxClientWidgetHashTable); wxDELETE(wxClientWidgetHashTable);
wxAppBase::CleanUp();
} }
wxApp::wxApp() wxApp::wxApp()
@ -789,11 +789,3 @@ Window wxGetWindowParent(Window window)
return (Window) 0; return (Window) 0;
#endif #endif
} }
void wxApp::Exit()
{
wxApp::CleanUp();
wxAppConsole::Exit();
}