|
From: <fli...@li...> - 2026-07-31 22:16:56
|
unknown user pushed a commit to branch release/2024.1
in repository flightgear.
The following commit(s) were added to refs/heads/release/2024.1 by this push:
new c9b51b88f Attempt to fix FGVoiceMgr::shutdown crashes
c9b51b88f is described below
SF URL: http://sourceforge.net/p/flightgear/flightgear/ci/c9b51b88f271b0473b2368392c25444cdf9857a2/
Commit: c9b51b88f271b0473b2368392c25444cdf9857a2
Author: James Turner
Committer: James Turner
AuthorDate: Thu Jul 30 16:40:18 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 9499cbad5..7b122f1ba 100644
--- a/src/Sound/flitevoice.cxx
+++ b/src/Sound/flitevoice.cxx
@@ -47,7 +47,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 441ba6370..225e68d7a 100644
--- a/src/Sound/voice.cxx
+++ b/src/Sound/voice.cxx
@@ -104,6 +104,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();
}
@@ -168,7 +172,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));
}
@@ -179,6 +183,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 60b73644b..873499c92 100644
--- a/src/Sound/voice.hxx
+++ b/src/Sound/voice.hxx
@@ -99,7 +99,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);
@@ -107,8 +107,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;
|