]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bootstrap.cxx
Reset, fix Nasal timers added on shutdown.
[flightgear.git] / src / Main / bootstrap.cxx
index 2b5cb2b262c062372f233b5d23da6e075392028e..fe988d7e34f37552406b16ab6a82934b5fb15324 100644 (file)
@@ -50,6 +50,9 @@
 #include <simgear/compiler.h>
 #include <simgear/structure/exception.hxx>
 
+#include <osg/Texture>
+#include <osg/BufferObject>
+
 #include <cstring>
 #include <iostream>
 using std::cerr;
@@ -64,7 +67,7 @@ using std::endl;
 #include "fg_os.hxx"
 
 #if defined(SG_MAC)
-#include <Carbon/Carbon.h> 
+    #include <GUI/CocoaHelpers.h> // for transformToForegroundApp
 #endif
 
 std::string homedir;
@@ -164,9 +167,7 @@ int main ( int argc, char **argv )
 #if defined(SG_MAC)
     // required so native messages boxes work prior to osgViewer init
     // (only needed when not running as a bundled app)
-    ProcessSerialNumber sn = { 0, kCurrentProcess };
-    TransformProcessType(&sn,kProcessTransformToForegroundApplication);
-    SetFrontProcess(&sn);
+    transformToForegroundApp();
 #endif
     
 #ifdef PTW32_STATIC_LIB
@@ -211,6 +212,12 @@ int main ( int argc, char **argv )
         // is possible inside fgExitCleanup
         sglog();
         
+        // similar to above, ensure some static maps inside OSG exist before
+        // we register our at-exit handler, otherwise the statics are gone
+        // when fg_terminate runs, which causes crashes.
+        osg::Texture::getTextureObjectManager(0);
+        osg::GLBufferObjectManager::getGLBufferObjectManager(0);
+        
         std::set_terminate(fg_terminate);
         atexit(fgExitCleanup);
         if (fgviewer)
@@ -245,9 +252,12 @@ int main ( int argc, char **argv )
 // so OpenAL device and context are released cleanly
 void fgExitCleanup() {
 
-    if (_bootstrap_OSInit != 0)
+    if (_bootstrap_OSInit != 0) {
         fgSetMouseCursor(MOUSE_CURSOR_POINTER);
 
+        fgOSCloseWindow();
+    }
+    
     // on the common exit path globals is already deleted, and NULL,
     // so this only happens on error paths.
     delete globals;