Hello,
I have object that I want to be ValueTree::Listener
, but I override only one method:
valueTreeChildAdded(ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
But after callback of that method I am sure my object doesn’t need to be listener anymore. So is it good idea to remove this
listener inside valueTreeChildAdded()
. It would look like that:
void valueTreeChildAdded(ValueTree& parentTree, ValueTree& childWhichHasBeenAdded)
{
singletonWhichKeepsParentTreeWithThisListener::getInstance()->parentTree.removeListener(this);
// I can't call directly input parameter parentTree.removeListener(this),
// because that parentTree is of course the same ValueTree
// but it is reference to another instance which
// doesn't contain "this" listener
// Here I do something with childWhichHasBeenAdded object
}
Above code works fine but I am not sure if it’s safe. Because valueTreeChildAdded
is called from loop through all listeners, so when I remove listener here it is like I remove listener inside loop through all listeners.
It is difficult for me to debug it while there are some lambdas and references objects which I feel like I don’t understand. That’s why I would like ask you for advice.
For any help great thanks in advance.