From 2a610d77e7e890914a8637ffafe92153c51e4177 Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 24 Aug 2004 08:40:41 +0000 Subject: [PATCH] Move the atexit() handler over to bootstrap.cxx (which makes libMain.a behave like a real library) and fix a segmentation fault when running 'fgfs -h'. The exit handler tried to change the (still uninitialized) mouse cursor causing a core dump. --- src/Main/bootstrap.cxx | 19 +++++++++++++++++++ src/Main/main.cxx | 16 +++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index 88664bd8d..743fc611a 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -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 // -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; +} diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 2fccf1ea3..3e8550d6e 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -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 ); -- 2.39.5