From 053e761d8fb6490b313a5e7d39bede92b7a2d388 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 3 Dec 2013 21:34:23 +0000 Subject: [PATCH] Reset: don't leak EffectPropertyListener. Track and free listeners from effect expressions. --- simgear/scene/material/Effect.cxx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index 669898aa..17b02a65 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -1358,14 +1358,25 @@ template class PropertyExpression : public SGExpression { public: - PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode) {} + PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode), _listener(NULL) {} + + ~PropertyExpression() + { + delete _listener; + } void eval(T& value, const expression::Binding*) const { value = _pnode->getValue(); } + + void setListener(SGPropertyChangeListener* l) + { + _listener = l; + } protected: SGPropertyNode_ptr _pnode; + SGPropertyChangeListener* _listener; }; class EffectPropertyListener : public SGPropertyChangeListener @@ -1378,6 +1389,9 @@ public: if (_tniq.valid()) _tniq->refreshValidity(); } + + virtual ~EffectPropertyListener() { } + protected: osg::observer_ptr _tniq; }; @@ -1391,9 +1405,12 @@ Expression* propertyExpressionParser(const SGPropertyNode* exp, PropertyExpression* pexp = new PropertyExpression(pnode); TechniquePredParser* predParser = dynamic_cast(parser); - if (predParser) - pnode->addChangeListener(new EffectPropertyListener(predParser - ->getTechnique())); + if (predParser) { + EffectPropertyListener* l = new EffectPropertyListener(predParser + ->getTechnique()); + pexp->setListener(l); + pnode->addChangeListener(l); + } return pexp; }