Reset: don't leak EffectPropertyListener.

Track and free listeners from effect expressions.
This commit is contained in:
James Turner 2013-12-03 21:34:23 +00:00
parent 5861b52cff
commit 053e761d8f

View File

@ -1358,14 +1358,25 @@ template<typename T>
class PropertyExpression : public SGExpression<T> class PropertyExpression : public SGExpression<T>
{ {
public: public:
PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode) {} PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode), _listener(NULL) {}
~PropertyExpression()
{
delete _listener;
}
void eval(T& value, const expression::Binding*) const void eval(T& value, const expression::Binding*) const
{ {
value = _pnode->getValue<T>(); value = _pnode->getValue<T>();
} }
void setListener(SGPropertyChangeListener* l)
{
_listener = l;
}
protected: protected:
SGPropertyNode_ptr _pnode; SGPropertyNode_ptr _pnode;
SGPropertyChangeListener* _listener;
}; };
class EffectPropertyListener : public SGPropertyChangeListener class EffectPropertyListener : public SGPropertyChangeListener
@ -1378,6 +1389,9 @@ public:
if (_tniq.valid()) if (_tniq.valid())
_tniq->refreshValidity(); _tniq->refreshValidity();
} }
virtual ~EffectPropertyListener() { }
protected: protected:
osg::observer_ptr<Technique> _tniq; osg::observer_ptr<Technique> _tniq;
}; };
@ -1391,9 +1405,12 @@ Expression* propertyExpressionParser(const SGPropertyNode* exp,
PropertyExpression<T>* pexp = new PropertyExpression<T>(pnode); PropertyExpression<T>* pexp = new PropertyExpression<T>(pnode);
TechniquePredParser* predParser TechniquePredParser* predParser
= dynamic_cast<TechniquePredParser*>(parser); = dynamic_cast<TechniquePredParser*>(parser);
if (predParser) if (predParser) {
pnode->addChangeListener(new EffectPropertyListener(predParser EffectPropertyListener* l = new EffectPropertyListener(predParser
->getTechnique())); ->getTechnique());
pexp->setListener(l);
pnode->addChangeListener(l);
}
return pexp; return pexp;
} }