From d6e452ea08df935e886a3b4db63799f2a95f22de Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 29 Jul 2021 15:21:39 +0100 Subject: [PATCH] Fix a ref-count loop in Paticles manager --- simgear/scene/model/particles.cxx | 8 ++++++++ simgear/scene/model/particles.hxx | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/simgear/scene/model/particles.cxx b/simgear/scene/model/particles.cxx index 8dee9e7f..0c7b774f 100644 --- a/simgear/scene/model/particles.cxx +++ b/simgear/scene/model/particles.cxx @@ -516,6 +516,14 @@ void Particles::setupStaticColorComponent(float r1, float g1, float b1, float a1 staticColorComponents[7] = a2; } +ParticlesGlobalManager::~ParticlesGlobalManager() +{ + // break a ref-counting cycle + if (d->_commonRoot) { + d->_commonRoot->removeUpdateCallback(d.get()); + } +} + void ParticlesGlobalManager::setWindVector(const osg::Vec3& wind) { std::lock_guard g(d->_lock); diff --git a/simgear/scene/model/particles.hxx b/simgear/scene/model/particles.hxx index b5af333f..f99ba832 100644 --- a/simgear/scene/model/particles.hxx +++ b/simgear/scene/model/particles.hxx @@ -150,7 +150,7 @@ protected: class ParticlesGlobalManager { public: - ~ParticlesGlobalManager() = default; + ~ParticlesGlobalManager(); static ParticlesGlobalManager* instance(); static void clear();