]> git.saurik.com Git - wxWidgets.git/commitdiff
use (new) safer GetTraitsIfExists() in wxMutexGuiEnter/Leave() to avoid crashing...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 21 Jul 2008 01:35:00 +0000 (01:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 21 Jul 2008 01:35:00 +0000 (01:35 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54735 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/app.h
src/common/appbase.cpp

index 5f4d622bae14cf5c74ec389c9730fbbba7e69a4c..ef542febc3825c17ff2b6910f23a325fc9c722cc 100644 (file)
@@ -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
     // --------------------------
index 1efd57adddb6bd1cc567ed083c5a71241bc97e74..54cc271c41f14b70380730401a736a7a50eefec2 100644 (file)
@@ -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