]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/init.cpp
Applied patch [ 864469 ] WaitForAccept(): 100% CPU Usage (NON-GUI application)
[wxWidgets.git] / src / common / init.cpp
index 2fd5771f0437750a0cc27538753c7e415d37d608..a67f723b64e2813dc9a1373506b49844fdd0c005 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "wx/ptr_scpd.h"
 #include "wx/module.h"
 
 #include "wx/ptr_scpd.h"
 #include "wx/module.h"
+#include "wx/except.h"
 
 #if defined(__WXMSW__) && defined(__WXDEBUG__)
     #include "wx/msw/msvcrt.h"
 
 #if defined(__WXMSW__) && defined(__WXDEBUG__)
     #include "wx/msw/msvcrt.h"
@@ -393,20 +394,29 @@ int wxEntryReal(int& argc, wxChar **argv)
 
     WX_SUPPRESS_UNUSED_WARN(cleanupOnExit);
 
 
     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;
+
+        WX_SUPPRESS_UNUSED_WARN(callOnExit);
 
 
-    return retValue;
+        // app execution
+        return wxTheApp->OnRun();
+    }
+    wxCATCH_ALL( wxTheApp->OnUnhandledException(); return -1; )
 }
 
 // wrap real wxEntry in a try-except block to be able to call
 }
 
 // wrap real wxEntry in a try-except block to be able to call