AudioProcessorValueTreeState crashes plugin if asked to retrieve nonexistent parameter

Hello everyone,

In my current project, I’m using AudioProcessorValueTreeState to store several parameters. I have a float pointer for each. For one of my parameters, I had a typo in the parameter’s string name in my call to getRawParameterValue() when running a line like this:

float* paramListener = (float*)(tree.getRawParameterValue("nameWithTypo"));

and this caused my plugin to crash the AudioPluginHost when attempting to scan for new plugins. It took me a little while to find the source of the error, because the crash report I was getting read “Pointer being realloc’d was not allocated”, so the error wasn’t obvious to me…

Yes, this was obviously my error, but my suggestion is that it might be possible to have Juce throw a compiler warning, or something of the sort, for things like this (asking APVTS to retrieve the value of a nonexistent parameter) instead of allowing the plugin to build and then crash…? Or perhaps a more descriptive crash message if this is the source of the abort? I know almost nothing about library creation, so apologies if this is a dumb suggestion or anything, I was just thinking this might save someone else some grief down the line.

The problem cannot be detected at compile time. The code has to actually execute to traverse the tree in order to find the parameter (or not). You can always check for NULL yourself before using that pointer.

1 Like

First of all, what are you doing there? Casting a pointer to a std::atomic<float> to a plain float pointer? :astonished:

You are lucky that this works at all and does not produce super weird crashes – you should definitively change that.

To avoid such kind of typos, I’d recommend storing the parameter ids as static const strings somewhere in a central place of your code and always refer to that variable instead of specifying the string directly as arguments. For some inspiration, here is how I structured it in my last open source plugin


Usage:

2 Likes

@PluginPenguin thank you for this! The way I had it set up was based on a tutorial (I’m still new to JUCE) and this does indeed work much better!

Thank you!