I’m having a tough time with ValueTree listeners, particularly when using removeListener, which is causing crashes in wrapped iterator when shutting down. The ValueTree I’m using originates in the Processor and gets passed to many classes including the voices in the juce Synth structure. All of my addListeners are in the constructors assigned as customData(cData) during construction, and all of the removeListeners are in the deconstructions. I’ve found that using a listener in voice class causes a lot of these issues & so have refrained from that, but it also affects classes which were passed in during construction which also originate in the processor class. The behaviour is erratic, it is different classes that cause the errors each time. I’ve tried commenting out all of the addListener/removeListeners and the crashes don’t happen. All of my passed classes are in unique/shared ptrs. I’m at a total loss as to why it happens, seems I’m missing something.
As I understand it, every addListener should have a paired removeListener in the deconstructor? If anyone has any advice on why this could be happening I’d be appreciative, I’ve been trying to solve it in & off for days & starting wonder about scrapping ValueTrees altogether, although I’m not sure how else to achieve the functionality they provide. I do pass the VT to the GUI & have issues there too sporadically when shutting down the Editor, it will poof Studio One for example.
I do use APVTS, but the valueTree I’m talking about is not part of it, I keep it separate & add/remove to the save state manually. The reason I do that is because the replace state breaks all listeners in the .state but seems fine with the parameters as far as I’m aware & so I can replace that state, and iterate through the values of my separate ValueTree manually updating each value.
Here is an example error, they are mostly the same but from different classes each time, always related to ValueTree listeners:
0x2ab6488ac juce::ListenerList<juce::ValueTree::Listener, juce::Array<juce::ValueTree::Listener*, juce::DummyCriticalSection, 0>>::WrappedIterator::invalidate() + 12