Proper way to listen to AutomatableParameter in the main thread

Hi, I’m making UI components for automatable parameters and I’m hitting a real time crash. Basically, my component registers itself as an automatable parameter listener in order to react to changes of the parameter. However, I’m sometimes hitting a real time crash that occurs when the component registers itself as a listener while the real time threads is processing the plugin’s node. Specifically, the crash occurs because the updateFromAutomationSources calls setParameterValue which in turn calls the listeners. If the main thread is currently registering, then it causes a segfault because it seems that the listener array has a dummy lock.

So I wonder what is the proper way to do it ?

The approach I’m leaning towards would be to not listen at all to the AutomatableParameter and just regularly poll its values (which should be thread safe as they are atomic). However it seems a bit weird to not use the existing listening API.

Another approach would be to have a way to lock the AutomatableParameter when registering to it as a listener but this seems a bad idea as it would lead to a priority inversion.

So what is the proper way to do it ? Am I missing something obvious ?

Thanks :slight_smile:

This sound like a bug either we have already fixed on a branch or need to fix.

Can you show some example code I could use to replicate this please?

Hi ! I’m on commit 80aeaf352fa92e95dfd1a3c6182c05269bd26cd4 on tracktion and commit 8ed3618e12230ad8563098e1f17575239497b127 on juce.

It’s difficult to extract the behavior from the codebase though. However I’m wondering if it could be related to the fact that I use SafeSelectable in order to have a WeakReference of the AutomatableParameter in the component ? Could it be a bad idea and the source of the problem ? Maybe I should instead keep track of the AutomatableEditItemId and the parameter name in the plugin’s value tree ?

I’ll continue investigating in the meantime and keep you up to date !

Yeah, as I thought this is something we have fixed on our technical-preview branch of TE 3.0. You can see the relevant change here:

We’re in the process of wrapping up development on this branch so it will become the new develop/main in the next few weeks.

Great to hear ! I’ll leave it as is for now then and wait for the update to be released.

Thanks !