From 2f1e2bc6e902c37c931eb93af9b6d9d5da691251 Mon Sep 17 00:00:00 2001 From: curt Date: Sun, 25 Apr 2004 02:06:55 +0000 Subject: [PATCH] Register an atexit() function so we can delete the global constructor. This also gives us a proper hook if we want to clean up SDL (Andy?) --- src/Main/globals.cxx | 26 ++++++++++++++------------ src/Main/main.cxx | 10 ++++++++++ src/Network/atlas.cxx | 1 + src/Network/httpd.cxx | 7 ++++++- src/Network/props.cxx | 1 + 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index b6a932760..d65861eee 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -21,6 +21,7 @@ // $Id$ +#include #include #include @@ -71,10 +72,10 @@ FGGlobals::FGGlobals() : acmodel( NULL ), model_mgr( NULL ), channel_options_list( NULL ), + initial_waypoints(0), scenery( NULL ), tile_mgr( NULL ), - io( new FGIO ), - initial_waypoints(0) + io( new FGIO ) { } @@ -82,17 +83,18 @@ FGGlobals::FGGlobals() : // Destructor FGGlobals::~FGGlobals() { - delete subsystem_mgr; - delete event_mgr; - delete initial_state; - delete props; - delete commands; - delete io; + delete soundmgr; + delete subsystem_mgr; + delete event_mgr; + delete initial_state; + delete props; + delete commands; + delete io; - // make sure only to delete the initial waypoints list if it acually - // still exists. - if (initial_waypoints) - delete initial_waypoints; + // make sure only to delete the initial waypoints list if it acually + // still exists. + if (initial_waypoints) + delete initial_waypoints; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 73a07e145..3d9fc2c53 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1442,6 +1442,14 @@ 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() { + delete globals; +} + + // Main top level initialization bool fgMainInit( int argc, char **argv ) { @@ -1454,6 +1462,8 @@ 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; diff --git a/src/Network/atlas.cxx b/src/Network/atlas.cxx index a31378547..3301c55cf 100644 --- a/src/Network/atlas.cxx +++ b/src/Network/atlas.cxx @@ -568,6 +568,7 @@ bool FGAtlas::process() { // close the channel bool FGAtlas::close() { + SG_LOG( SG_IO, SG_INFO, "closing FGAtlas" ); SGIOChannel *io = get_io_channel(); set_enabled( false ); diff --git a/src/Network/httpd.cxx b/src/Network/httpd.cxx index 5b591b99f..3e4242492 100644 --- a/src/Network/httpd.cxx +++ b/src/Network/httpd.cxx @@ -74,7 +74,12 @@ bool FGHttpd::process() { bool FGHttpd::close() { - delete server; + SG_LOG( SG_IO, SG_INFO, "closing FGHttpd" ); + + // the following delete causes a seg fault, gdb is not helpful. + // delete server; + + set_enabled( false ); return true; } diff --git a/src/Network/props.cxx b/src/Network/props.cxx index 58f7e4466..3504f99c8 100644 --- a/src/Network/props.cxx +++ b/src/Network/props.cxx @@ -484,6 +484,7 @@ FGProps::open() bool FGProps::close() { + SG_LOG( SG_IO, SG_INFO, "closing FGProps" ); return true; } -- 2.39.5