]> git.mxchange.org Git - simgear.git/commitdiff
Reset: don't leak EffectPropertyListener.
authorJames Turner <zakalawe@mac.com>
Tue, 3 Dec 2013 21:34:23 +0000 (21:34 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 3 Dec 2013 21:36:18 +0000 (21:36 +0000)
Track and free listeners from effect expressions.

simgear/scene/material/Effect.cxx

index 669898aadb7e50506c20bc242c02cff284c9b069..17b02a65a8e878e6d0d1cbb788cae66d860cf34c 100644 (file)
@@ -1358,14 +1358,25 @@ template<typename T>
 class PropertyExpression : public SGExpression<T>
 {
 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<T>();
     }
+    
+    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<Technique> _tniq;
 };
@@ -1391,9 +1405,12 @@ Expression* propertyExpressionParser(const SGPropertyNode* exp,
     PropertyExpression<T>* pexp = new PropertyExpression<T>(pnode);
     TechniquePredParser* predParser
         = dynamic_cast<TechniquePredParser*>(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;
 }