I have discovered the concept of juce’s Value object just a couple of weeks ago (thanks to Jules’ answer to one of my threads) and found it incredibly powerful. I have been able to drastically reduce the size of my code, but I must say I do not quite fully get how it’s meant to be used.
I have come across an interesting problem. My application currently crashes on shutdown and I have tracked the problem down to TextEditor destructor. There’s this line:
textValue.referTo (Value());
Well. My problem is obvious and I know how to solve it but since I am at it, I’d like to know more about the philosophy of the Value::Listener(s).
Here the problem is that the line mentioned above causes all the listeners to be informed. In my case the listener no longer exists. I have all my components in some OwnedArray and in this case the Listener were positioned before the TextEditor so it was freed earlier. That is, if I swapped those two objects in the array it would help, but that is of course not the point. So there are two questions:
- Why is there the line mentioned above in the TextEditor destructor. What is it supposed to do?
- How are the Values and their Listeners supposed to work, do I always need to unregister all the listeners before deleting the object? I ask this because I have seen something called valuesWithListeners in the Value class and I don’t understand what is it for, but at first glance it seemed to me that it might have something to do with unregistering the listeners…
Thanks!