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);
#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;
}

View 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 );