]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/init.cpp
cleanup in toplevel activation, and switching to native carbon event notification...
[wxWidgets.git] / src / common / init.cpp
index 2fd5771f0437750a0cc27538753c7e415d37d608..e6d803cbe432f2354e59d41b763123ad6151a55d 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "wx/ptr_scpd.h"
 #include "wx/module.h"
+#include "wx/except.h"
 
 #if defined(__WXMSW__) && defined(__WXDEBUG__)
     #include "wx/msw/msvcrt.h"
@@ -337,16 +338,7 @@ static void DoCommonPostCleanup()
     FreeConvertedArgs();
 #endif // wxUSE_UNICODE
 
-    // check for memory leaks
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
-    if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
-    {
-        wxLogDebug(wxT("There were memory leaks.\n"));
-        wxDebugContext::Dump();
-        wxDebugContext::PrintStatistics();
-    }
-#endif // Debug
-
+    // Note: check for memory leaks is now done via wxDebugContextDumpDelayCounter
 #if wxUSE_LOG
     // and now delete the last logger as well
     delete wxLog::SetActiveTarget(NULL);
@@ -393,20 +385,29 @@ int wxEntryReal(int& argc, wxChar **argv)
 
     WX_SUPPRESS_UNUSED_WARN(cleanupOnExit);
 
-    // app initialization
-    if ( !wxTheApp->CallOnInit() )
+    wxTRY
     {
-        // don't call OnExit() if OnInit() failed
-        return -1;
-    }
 
-    // app execution
-    int retValue = wxTheApp->OnRun();
+        // app initialization
+        if ( !wxTheApp->CallOnInit() )
+        {
+            // don't call OnExit() if OnInit() failed
+            return -1;
+        }
 
-    // app clean up
-    wxTheApp->OnExit();
+        // ensure that OnExit() is called if OnInit() had succeeded
+        class CallOnExit
+        {
+        public:
+            ~CallOnExit() { wxTheApp->OnExit(); }
+        } callOnExit;
 
-    return retValue;
+        WX_SUPPRESS_UNUSED_WARN(callOnExit);
+
+        // app execution
+        return wxTheApp->OnRun();
+    }
+    wxCATCH_ALL( wxTheApp->OnUnhandledException(); return -1; )
 }
 
 // wrap real wxEntry in a try-except block to be able to call