diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index 8a360206e..fb95b8f19 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -241,6 +241,8 @@ int main ( int argc, char **argv ) { fgviewerMain(argc, argv); else fgMainInit(argc, argv); + + } catch (const sg_throwable &t) { // We must use cerr rather than // logging, since logging may be diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 354a92bc0..1fe2c4ce4 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -211,7 +211,8 @@ do_exit (const SGPropertyNode * arg) SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings"); } } - fgExit(arg->getIntValue("status", 0)); + + fgOSExit(arg->getIntValue("status", 0)); return true; } diff --git a/src/Main/fg_os.hxx b/src/Main/fg_os.hxx index 62f6f8f7d..ebeb0701b 100644 --- a/src/Main/fg_os.hxx +++ b/src/Main/fg_os.hxx @@ -60,7 +60,7 @@ enum { KEYMOD_NONE = 0, void fgOSInit(int* argc, char** argv); void fgOSOpenWindow(bool stencil); void fgOSFullScreen(); -void fgOSMainLoop(); +int fgOSMainLoop(); void fgOSExit(int code); void fgSetMouseCursor(int cursor); diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index a03cc747e..726c868a9 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -271,7 +271,7 @@ void fgOSExit(int code) status = code; } -void fgOSMainLoop() +int fgOSMainLoop() { ref_ptr manipulator = globals->get_renderer()->getEventHandler(); @@ -287,7 +287,8 @@ void fgOSMainLoop() (*drawFunc)(); viewer->frame(); } - fgExit(status); + + return status; } int fgGetKeyModifiers() diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 894dd0010..b9c0f194f 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -576,7 +576,7 @@ static void upper_case_property(const char *name) // Main top level initialization -bool fgMainInit( int argc, char **argv ) { +int fgMainInit( int argc, char **argv ) { // set default log levels sglog().setLogLevels( SG_ALL, SG_ALERT ); @@ -660,11 +660,14 @@ bool fgMainInit( int argc, char **argv ) { fgSplashInit(); // pass control off to the master event handler - fgOSMainLoop(); - - // we never actually get here ... but to avoid compiler warnings, - // etc. - return false; + int result = fgOSMainLoop(); + + // clean up here; ensure we null globals to avoid + // confusing the atexit() handler + delete globals; + globals = NULL; + + return result; } diff --git a/src/Main/main.hxx b/src/Main/main.hxx index 2117f605b..115b3c628 100644 --- a/src/Main/main.hxx +++ b/src/Main/main.hxx @@ -4,7 +4,7 @@ void fgUpdateTimeDepCalcs(); -bool fgMainInit( int argc, char **argv ); +int fgMainInit( int argc, char **argv ); extern int idle_state; diff --git a/src/Main/util.cxx b/src/Main/util.cxx index 0986e91ea..7c20530a3 100644 --- a/src/Main/util.cxx +++ b/src/Main/util.cxx @@ -105,19 +105,6 @@ fgSetupWind (double min_hdg, double max_hdg, double speed, double gust) speed); } - -void -fgExit (int status) -{ -#ifdef OSG_LIBRARY_STATIC - osgDB::Registry::instance( true); -#endif - - SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status); - std::exit(status); -} - - // Originally written by Alex Perry. double fgGetLowPass (double current, double target, double timeratio) diff --git a/src/Main/util.hxx b/src/Main/util.hxx index 70067d3e3..dcd75b130 100644 --- a/src/Main/util.hxx +++ b/src/Main/util.hxx @@ -49,17 +49,6 @@ extern void fgDefaultWeatherValue (const char * propname, double value); extern void fgSetupWind (double min_hdg, double max_hdg, double speed, double gust); -/** - * Clean up and exit FlightGear. - * - * This function makes sure that network connections and I/O streams - * are cleaned up. - * - * @param status The exit status to pass to the operating system. - */ -extern void fgExit (int status = 0); - - /** * Move a value towards a target. * diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index 423d2be18..034a94fa6 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -37,8 +37,8 @@ #include
#include
+#include
#include
- #include "generic.hxx" @@ -490,7 +490,7 @@ bool FGGeneric::process() { return true; error_out: if (exitOnError) { - fgExit(1); + fgOSExit(1); return true; // should not get there, but please the compiler } else return false;