]> git.mxchange.org Git - flightgear.git/commitdiff
Move the atexit() handler over to bootstrap.cxx (which makes libMain.a behave like...
authorehofman <ehofman>
Tue, 24 Aug 2004 08:40:41 +0000 (08:40 +0000)
committerehofman <ehofman>
Tue, 24 Aug 2004 08:40:41 +0000 (08:40 +0000)
src/Main/bootstrap.cxx
src/Main/main.cxx

index 88664bd8dd958f719c38e75f7dfe83a6158b166b..743fc611aa0bf0b06ad5c51705d1fb227a5bd729 100644 (file)
@@ -41,6 +41,7 @@ SG_USING_STD(cerr);
 SG_USING_STD(endl);
 
 #include "main.hxx"
+#include "globals.hxx"
 
 
 #ifdef HAVE_WINDOWS_H
@@ -54,6 +55,8 @@ SG_USING_STD(endl);
 #  include <console.h>         // -dw- for command line dialog
 #endif
 
+// foreward declaration.
+void fgExitCleanup();
 
 #if defined(__linux__) && defined(__i386__)
 
@@ -133,9 +136,13 @@ void flush_fpe(void)
 }
 #endif
 
+int _bootstrap_OSInit;
+
 // Main entry point; catch any exceptions that have made it this far.
 int main ( int argc, char **argv ) {
 
+    _bootstrap_OSInit = 0;
+
     // Enable floating-point exceptions for Linux/x86
 #if defined(__linux__) && defined(__i386__)
     initFPE();
@@ -161,6 +168,7 @@ int main ( int argc, char **argv ) {
       PSN psn;
 
       fgOSInit (&argc, argv);
+      _bootstrap_OSInit++;
 
       CPSGetCurrentProcess(&psn);
       CPSSetProcessName(&psn, "FlightGear");
@@ -172,6 +180,7 @@ int main ( int argc, char **argv ) {
     // FIXME: add other, more specific
     // exceptions.
     try {
+        atexit(fgExitCleanup);
         fgMainInit(argc, argv);
     } catch (sg_throwable &t) {
                             // We must use cerr rather than
@@ -185,4 +194,14 @@ int main ( int argc, char **argv ) {
     return 0;
 }
 
+// do some clean up on exit.  Specifically we want to call alutExit()
+// which happens in the sound manager destructor.
+void fgExitCleanup() {
+
+    if (_bootstrap_OSInit != 0)
+        fgSetMouseCursor(MOUSE_CURSOR_POINTER);
+
+    if (globals)
+        delete globals;
+}
 
index 2fccf1ea3a541d0b36114f3fe6e9a3bfcf53fe49..3e8550d6e6878da7dce7dbfec8844d10e328e969 100644 (file)
@@ -167,6 +167,10 @@ ssgSimpleState *menus;
 SGTimeStamp last_time_stamp;
 SGTimeStamp current_time_stamp;
 
+// The atexit() functio handler should know when the graphical subsystem
+// is initialized.
+extern int _bootstrap_OSInit;
+
 
 void fgBuildRenderStates( void ) {
     default_state = new ssgSimpleState;
@@ -1504,15 +1508,6 @@ void fgReshape( int width, int height ) {
 }
 
 
-// do some clean up on exit.  Specifically we want to call alutExit()
-// which happens in the sound manager destructor.
-void fgExitCleanup() {
-    fgSetMouseCursor(MOUSE_CURSOR_POINTER);
-    delete globals;
-//    fgOSExit(0);
-}
-
-
 // Main top level initialization
 bool fgMainInit( int argc, char **argv ) {
 
@@ -1525,8 +1520,6 @@ bool fgMainInit( int argc, char **argv ) {
     // set default log levels
     sglog().setLogLevels( SG_ALL, SG_ALERT );
 
-    atexit(fgExitCleanup);
-
     string version;
 #ifdef FLIGHTGEAR_VERSION
     version = FLIGHTGEAR_VERSION;
@@ -1590,6 +1583,7 @@ bool fgMainInit( int argc, char **argv ) {
     // from main(), in bootstrap.cxx.  Andy doesn't know why, someone
     // feel free to add comments...
     fgOSInit(&argc, argv);
+    _bootstrap_OSInit++;
 #endif
 
     fgRegisterWindowResizeHandler( fgReshape );