]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bootstrap.cxx
Melchior FRANZ:
[flightgear.git] / src / Main / bootstrap.cxx
index 88664bd8dd958f719c38e75f7dfe83a6158b166b..5f2b24a54f149ee568cdf07996e26e331dcd64a5 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started May 1997.
 //
-// Copyright (C) 1997 - 2002  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 1997 - 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -31,6 +31,7 @@
 #endif
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #include <simgear/compiler.h>
 #include <simgear/structure/exception.hxx>
@@ -41,6 +42,7 @@ SG_USING_STD(cerr);
 SG_USING_STD(endl);
 
 #include "main.hxx"
+#include "globals.hxx"
 
 
 #ifdef HAVE_WINDOWS_H
@@ -54,6 +56,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 +137,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 +169,7 @@ int main ( int argc, char **argv ) {
       PSN psn;
 
       fgOSInit (&argc, argv);
+      _bootstrap_OSInit++;
 
       CPSGetCurrentProcess(&psn);
       CPSSetProcessName(&psn, "FlightGear");
@@ -172,6 +181,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
@@ -179,10 +189,22 @@ int main ( int argc, char **argv ) {
                             // disabled.
         cerr << "Fatal error: " << t.getFormattedMessage()
              << "\n (received from " << t.getOrigin() << ')' << endl;
-        exit(1);
+    } catch (...) {
+        cerr << "Unknown exception in the main loop. Aborting..." << endl;
+        perror("Possible cause");
     }
 
     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;
+}