1
0
Fork 0

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.

This commit is contained in:
ehofman 2004-08-24 08:40:41 +00:00
parent 83ca912de2
commit 2a610d77e7
2 changed files with 24 additions and 11 deletions

View file

@ -41,6 +41,7 @@ SG_USING_STD(cerr);
SG_USING_STD(endl); SG_USING_STD(endl);
#include "main.hxx" #include "main.hxx"
#include "globals.hxx"
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
@ -54,6 +55,8 @@ SG_USING_STD(endl);
# include <console.h> // -dw- for command line dialog # include <console.h> // -dw- for command line dialog
#endif #endif
// foreward declaration.
void fgExitCleanup();
#if defined(__linux__) && defined(__i386__) #if defined(__linux__) && defined(__i386__)
@ -133,9 +136,13 @@ void flush_fpe(void)
} }
#endif #endif
int _bootstrap_OSInit;
// Main entry point; catch any exceptions that have made it this far. // Main entry point; catch any exceptions that have made it this far.
int main ( int argc, char **argv ) { int main ( int argc, char **argv ) {
_bootstrap_OSInit = 0;
// Enable floating-point exceptions for Linux/x86 // Enable floating-point exceptions for Linux/x86
#if defined(__linux__) && defined(__i386__) #if defined(__linux__) && defined(__i386__)
initFPE(); initFPE();
@ -161,6 +168,7 @@ int main ( int argc, char **argv ) {
PSN psn; PSN psn;
fgOSInit (&argc, argv); fgOSInit (&argc, argv);
_bootstrap_OSInit++;
CPSGetCurrentProcess(&psn); CPSGetCurrentProcess(&psn);
CPSSetProcessName(&psn, "FlightGear"); CPSSetProcessName(&psn, "FlightGear");
@ -172,6 +180,7 @@ int main ( int argc, char **argv ) {
// FIXME: add other, more specific // FIXME: add other, more specific
// exceptions. // exceptions.
try { try {
atexit(fgExitCleanup);
fgMainInit(argc, argv); fgMainInit(argc, argv);
} catch (sg_throwable &t) { } catch (sg_throwable &t) {
// We must use cerr rather than // We must use cerr rather than
@ -185,4 +194,14 @@ int main ( int argc, char **argv ) {
return 0; 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;
}

View file

@ -167,6 +167,10 @@ ssgSimpleState *menus;
SGTimeStamp last_time_stamp; SGTimeStamp last_time_stamp;
SGTimeStamp current_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 ) { void fgBuildRenderStates( void ) {
default_state = new ssgSimpleState; 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 // Main top level initialization
bool fgMainInit( int argc, char **argv ) { bool fgMainInit( int argc, char **argv ) {
@ -1525,8 +1520,6 @@ bool fgMainInit( int argc, char **argv ) {
// set default log levels // set default log levels
sglog().setLogLevels( SG_ALL, SG_ALERT ); sglog().setLogLevels( SG_ALL, SG_ALERT );
atexit(fgExitCleanup);
string version; string version;
#ifdef FLIGHTGEAR_VERSION #ifdef FLIGHTGEAR_VERSION
version = 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 // from main(), in bootstrap.cxx. Andy doesn't know why, someone
// feel free to add comments... // feel free to add comments...
fgOSInit(&argc, argv); fgOSInit(&argc, argv);
_bootstrap_OSInit++;
#endif #endif
fgRegisterWindowResizeHandler( fgReshape ); fgRegisterWindowResizeHandler( fgReshape );