From 96b2cbe8b39292fed91654ff0d1f4b1c16561acb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Jul 2008 01:35:00 +0000 Subject: [PATCH] use (new) safer GetTraitsIfExists() in wxMutexGuiEnter/Leave() to avoid crashing on exit of wxGTK1 applications putting anything on clipboard (and maybe other cases) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54735 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 7 +++++++ src/common/appbase.cpp | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index 5f4d622bae..ef542febc3 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -198,6 +198,13 @@ public: // allows us to abstract the differences behind the common facade wxAppTraits *GetTraits(); + // this function provides safer access to traits object than + // wxTheApp->GetTraits() during startup or termination when the global + // application object itself may be unavailable + // + // of course, it still returns NULL in this case and the caller must check + // for it + static wxAppTraits *GetTraitsIfExists(); // event processing functions // -------------------------- diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 1efd57addd..54cc271c41 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -290,6 +290,13 @@ wxAppTraits *wxAppConsoleBase::GetTraits() return m_traits; } +/* static */ +wxAppTraits *wxAppConsoleBase::GetTraitsIfExists() +{ + wxAppConsole * const app = GetInstance(); + return app ? app->GetTraits() : NULL; +} + // ---------------------------------------------------------------------------- // event processing // ---------------------------------------------------------------------------- @@ -673,12 +680,16 @@ void wxAppTraitsBase::MutexGuiLeave() void WXDLLIMPEXP_BASE wxMutexGuiEnter() { - wxAppConsoleBase::GetInstance()->GetTraits()->MutexGuiEnter(); + wxAppTraits * const traits = wxAppConsoleBase::GetTraitsIfExists(); + if ( traits ) + traits->MutexGuiEnter(); } void WXDLLIMPEXP_BASE wxMutexGuiLeave() { - wxAppConsoleBase::GetInstance()->GetTraits()->MutexGuiLeave(); + wxAppTraits * const traits = wxAppConsoleBase::GetTraitsIfExists(); + if ( traits ) + traits->MutexGuiLeave(); } #endif // wxUSE_THREADS