|
From: <fli...@li...> - 2026-07-30 21:32:06
|
unknown user pushed a commit to branch next
in repository flightgear.
The following commit(s) were added to refs/heads/next by this push:
new 3c25427a3 Attempt to fix FGVoiceMgr::shutdown crashes
3c25427a3 is described below
SF URL: http://sourceforge.net/p/flightgear/flightgear/ci/3c25427a395f9231742d0c4a65dc22a130f15a8c/
Commit: 3c25427a395f9231742d0c4a65dc22a130f15a8c
Author: James Turner
Committer: James Turner
AuthorDate: Thu Jul 30 22:31:57 2026 +0100
Attempt to fix FGVoiceMgr::shutdown crashes
---
src/Sound/flitevoice.cxx | 2 +-
src/Sound/voice.cxx | 18 +++++++++++++++++-
src/Sound/voice.hxx | 6 +++++-
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/src/Sound/flitevoice.cxx b/src/Sound/flitevoice.cxx
index 35e7fead3..7ab4dc803 100644
--- a/src/Sound/flitevoice.cxx
+++ b/src/Sound/flitevoice.cxx
@@ -31,7 +31,7 @@ FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, cons
_sgr = smgr->find(sampleGroupRefName, true);
_sgr->tie_to_listener();
- node->getNode("text", true)->addChangeListener(this);
+ listenOnTextNode(node->getNode("text", true));
SG_LOG(SG_SOUND, SG_DEBUG, "FLITEVoice initialized for sample-group '" << sampleGroupRefName
<< "'. Samples will be named '" << _sampleName << "' "
diff --git a/src/Sound/voice.cxx b/src/Sound/voice.cxx
index 4d8fb04cd..1bded0709 100644
--- a/src/Sound/voice.cxx
+++ b/src/Sound/voice.cxx
@@ -102,6 +102,10 @@ void FGVoiceMgr::shutdown()
for( std::vector<FGVoice*>::iterator it = _voices.begin(); it != _voices.end(); ++it )
delete *it;
+
+ // avoid dangling pointers/double-delete if shutdown() is ever called again
+ // (e.g. SGSubsystemGroup::shutdown() has no reentrancy guard)
+ _voices.clear();
}
@@ -166,7 +170,7 @@ FGFestivalVoice::FGFestivalVoice(FGVoiceMgr *mgr, const SGPropertyNode_ptr node)
setPitch(_pitch = _pitchNode->getDoubleValue());
setSpeed(_speed = _speedNode->getDoubleValue());
- node->getNode("text", true)->addChangeListener(this);
+ listenOnTextNode(node->getNode("text", true));
}
@@ -177,6 +181,18 @@ FGFestivalVoice::~FGFestivalVoice()
}
+FGVoiceMgr::FGVoice::~FGVoice()
+{
+ if (_textNode)
+ _textNode->removeChangeListener(this);
+}
+
+void FGVoiceMgr::FGVoice::listenOnTextNode(SGPropertyNode_ptr node)
+{
+ _textNode = node;
+ _textNode->addChangeListener(this);
+}
+
void FGVoiceMgr::FGVoice::pushMessage( const string & m)
{
_msg.push(m);
diff --git a/src/Sound/voice.hxx b/src/Sound/voice.hxx
index 60861c485..1eb575b78 100644
--- a/src/Sound/voice.hxx
+++ b/src/Sound/voice.hxx
@@ -84,7 +84,7 @@ class FGVoiceMgr::FGVoice : public SGPropertyChangeListener
{
public:
FGVoice(FGVoiceMgr * mgr ) : _mgr(mgr) {}
- virtual ~FGVoice() {}
+ virtual ~FGVoice();
virtual void speak( const std::string & msg ) = 0;
virtual void update(double dt) = 0;
void pushMessage( const std::string & m);
@@ -92,8 +92,12 @@ public:
protected:
void valueChanged(SGPropertyNode *node);
+ // register as change listener on the given node, and remember it so the
+ // listener can be removed again in ~FGVoice()
+ void listenOnTextNode(SGPropertyNode_ptr node);
FGVoiceMgr *_mgr;
+ SGPropertyNode_ptr _textNode;
#if defined(ENABLE_THREADS)
SGLockedQueue<std::string> _msg;
|