From 25bf3793bd6c6e97dd552351ace5a3c7e5896e4e Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 25 Nov 2013 23:53:58 +0000 Subject: [PATCH] Reset: fix a static in play-audio-sample Had to add this to FGGlobals, since it needs to be cleaned up alongside the sound manager (which ideally it would be owned by, but that's a change for another day) --- src/Main/fg_commands.cxx | 7 ++++--- src/Main/fg_init.cxx | 4 +++- src/Main/globals.cxx | 17 +++++++++++++++-- src/Main/globals.hxx | 7 ++++++- src/Sound/sample_queue.cxx | 4 ---- src/Sound/soundmanager.cxx | 2 ++ 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 6ae72a996..4c0f580b0 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1164,10 +1164,11 @@ do_play_audio_sample (const SGPropertyNode * arg) float volume = arg->getFloatValue("volume"); // cout << "playing " << path << " / " << file << endl; try { - static FGSampleQueue *queue = 0; + FGSampleQueue *queue = globals->get_chatter_queue(); if ( !queue ) { - queue = new FGSampleQueue(smgr, "chatter"); - queue->tie_to_listener(); + queue = new FGSampleQueue(smgr, "chatter"); + queue->tie_to_listener(); + globals->set_chatter_queue(queue); } SGSoundSample *msg = new SGSoundSample(file.c_str(), path); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index e9748c28c..ba816d21f 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -982,8 +982,10 @@ void fgStartNewReset() globals->set_renderer(NULL); globals->set_matlib(NULL); - simgear::SGModelLib::resetPropertyRoot(); + globals->set_chatter_queue(NULL); + simgear::SGModelLib::resetPropertyRoot(); + globals->resetPropertyRoot(); globals->restoreInitialState(); diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 51125d871..acfb0d629 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -53,6 +53,7 @@ #include #include #include +#include #include "globals.hxx" #include "locale.hxx" @@ -151,7 +152,8 @@ FGGlobals::FGGlobals() : initial_waypoints( NULL ), fontcache ( new FGFontCache ), channellist( NULL ), - haveUserSettings(false) + haveUserSettings(false), + _chatter_queue(NULL) { SGPropertyNode* root = new SGPropertyNode; props = SGPropertyNode_ptr(root); @@ -210,7 +212,8 @@ FGGlobals::~FGGlobals() // renderer touches subsystems during its destruction set_renderer(NULL); _scenery.clear(); - + _chatter_queue.clear(); + delete subsystem_mgr; subsystem_mgr = NULL; // important so ::get_subsystem returns NULL @@ -696,4 +699,14 @@ void FGGlobals::set_matlib( SGMaterialLib *m ) matlib = m; } +FGSampleQueue* FGGlobals::get_chatter_queue() const +{ + return _chatter_queue; +} + +void FGGlobals::set_chatter_queue(FGSampleQueue* queue) +{ + _chatter_queue = queue; +} + // end of globals.cxx diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 09275daae..3f8ae0689 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -66,7 +66,7 @@ class FGViewMgr; class FGViewer; class FGRenderer; class FGFontCache; - +class FGSampleQueue; /** * Bucket for subsystem pointers representing the sim's state. @@ -161,6 +161,8 @@ private: * helper to initialise standard properties on a new property tree */ void initProperties(); + + SGSharedPtr _chatter_queue; public: FGGlobals(); @@ -341,6 +343,9 @@ public: * Save user settings in autosave.xml */ void saveUserSettings(); + + FGSampleQueue* get_chatter_queue() const; + void set_chatter_queue(FGSampleQueue* queue); }; diff --git a/src/Sound/sample_queue.cxx b/src/Sound/sample_queue.cxx index e3aaae9f9..f6a1a49b5 100644 --- a/src/Sound/sample_queue.cxx +++ b/src/Sound/sample_queue.cxx @@ -50,10 +50,6 @@ FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const std::string &refname ) : FGSampleQueue::~FGSampleQueue () { - while ( ! _messages.empty() ) { - delete _messages.front(); - _messages.pop(); - } } diff --git a/src/Sound/soundmanager.cxx b/src/Sound/soundmanager.cxx index a4c197ce9..012642f66 100644 --- a/src/Sound/soundmanager.cxx +++ b/src/Sound/soundmanager.cxx @@ -91,6 +91,8 @@ void FGSoundManager::shutdown() SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true); scenery_loaded->removeChangeListener(_listener.get()); + stop(); + SGSoundMgr::shutdown(); } -- 2.39.5