From e115201066d2ffcecf8e63762efed632e4ebf533 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 10 Apr 2010 08:42:08 +0000 Subject: [PATCH 1/2] Delay loading of the voice file since the sound manager might not be initialized (at all). --- src/ATCDCL/ATCmgr.cxx | 55 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/ATCDCL/ATCmgr.cxx b/src/ATCDCL/ATCmgr.cxx index 9e5085adb..3ca5d16db 100644 --- a/src/ATCDCL/ATCmgr.cxx +++ b/src/ATCDCL/ATCmgr.cxx @@ -59,6 +59,12 @@ AirportATC::AirportATC() : FGATCMgr::FGATCMgr() : initDone(false), atc_list(new atc_list_type), +#ifdef ENABLE_AUDIO_SUPPORT + voiceOK(false), + voice(true), +#else + voice(false), +#endif last_in_range(false) { } @@ -89,30 +95,6 @@ void FGATCMgr::init() { // Is this still true after the reorganization of the event managar?? // -EMH- -#ifdef ENABLE_AUDIO_SUPPORT - // Load all available voices. - // For now we'll do one hardwired one - - v1 = new FGATCVoice; - try { - voiceOK = v1->LoadVoice("default"); - voice = true; - } catch ( sg_io_exception & e) { - voiceOK = false; - SG_LOG(SG_ATC, SG_ALERT, "Unable to load default voice : " << e.getFormattedMessage().c_str()); - voice = false; - delete v1; - v1 = 0; - } - - /* I've loaded the voice even if /sim/sound/pause is true - * since I know no way of forcing load of the voice if the user - * subsequently switches /sim/sound/audible to true. - * (which is the right thing to do -- CLO) :-) */ -#else - voice = false; -#endif - // Initialise the ATC Dialogs //cout << "Initing Transmissions..." << endl; SG_LOG(SG_ATC, SG_INFO, " ATC Transmissions"); @@ -421,6 +403,31 @@ FGATCVoice* FGATCMgr::GetVoicePointer(const atc_type& type) { if(voice) { switch(type) { case ATIS: case AWOS: +#ifdef ENABLE_AUDIO_SUPPORT + // Delayed loading fo all available voices, needed because the + // soundmanager might not be initialized (at all) at this point. + // For now we'll do one hardwired one + + /* I've loaded the voice even if /sim/sound/pause is true + * since I know no way of forcing load of the voice if the user + * subsequently switches /sim/sound/audible to true. + * (which is the right thing to do -- CLO) :-) + */ + if (!voiceOK && fgGetBool("/sim/sound/working")) { + v1 = new FGATCVoice; + try { + voiceOK = v1->LoadVoice("default"); + voice = voiceOK; + } catch ( sg_io_exception & e) { + voiceOK = false; + SG_LOG(SG_ATC, SG_ALERT, "Unable to load default voice : " + << e.getFormattedMessage().c_str()); + voice = false; + delete v1; + v1 = 0; + } + } +#endif if(voiceOK) { return(v1); } From 09f8ab61cf0a7760124813e30a3f8894cd56a149 Mon Sep 17 00:00:00 2001 From: fredb Date: Sat, 10 Apr 2010 20:58:58 +0000 Subject: [PATCH 2/2] Initialise v1 to avoid a segfault on exit --- src/ATCDCL/ATCmgr.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ATCDCL/ATCmgr.cxx b/src/ATCDCL/ATCmgr.cxx index 3ca5d16db..19053adef 100644 --- a/src/ATCDCL/ATCmgr.cxx +++ b/src/ATCDCL/ATCmgr.cxx @@ -65,7 +65,8 @@ FGATCMgr::FGATCMgr() : #else voice(false), #endif - last_in_range(false) + last_in_range(false), + v1(0) { }