Adding AudioParameterChoice crashes my plugin


#1

Hi,

I am trying to add AudioParameterChoice to my plugin. Here’s my very simple code (excerpt from my processor constructor):

StringArray choices = {"first", "second"};
choiceParam = new AudioParameterChoice("choice", "Choice", choices, 0);
addParameter(choiceParam);

Of course choiceParam is defined in header file as a pointer to AudioParameterChoice.

When I add my VST or VST3 plugin to track in DAW it crashes.

I tried using lldb, and here’s what I got:

* thread #1: tid = 0x12ef7b, 0x0000000109971f14 MyPlugin`juce::CharPointer_UTF8::CharPointer_UTF8(this=0x0000000101884ce8, other=0x0000000000000018) + 20 at juce_CharPointer_UTF8.h:42, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x18)
    frame #0: 0x0000000109971f14 MyPlugin`juce::CharPointer_UTF8::CharPointer_UTF8(this=0x0000000101884ce8, other=0x0000000000000018) + 20 at juce_CharPointer_UTF8.h:42
   39  	    }
   40
   41  	    inline CharPointer_UTF8 (const CharPointer_UTF8& other) noexcept
-> 42  	        : data (other.data)
   43  	    {
   44  	    }
   45

When I comment out addParameter line it works just fine. What’s wrong? :frowning:

EDIT: This post is no longer valid, I had an error in completely different part of my plugin which was by accident affected by new parameter :wink:


#2

Hi,

The documentation of addParameter() sais that:

The parameter object will be managed and deleted automatically by the list
when no longer needed.

If you keep a pointer to the AudioParameterChoice, and access that pointer after that the list of parameters has deleted it, then your plugin crashes.


#3

The AudioParameterChoice constructor takes a reference to the array, which means, it doesn’t copy but references the array (obviously :wink: )
After your constructor the StringArray goes out of scope and the choice parameter looks into the emptyness of free space.

HTH

@McMartin: it doesn’t hurt to have an additional pointer to the parameter, but I would also advice against it to avoid lifecycle problems


#4

Thanks. :slight_smile: But what’s so different about AudioParameterFloat that when I use it the same way as I did above it does not crash?

I am not accessing pointer to my AudioParameterChoice anywhere.
There’s some confusion regarding the tutorial: https://www.juce.com/doc/tutorial_audio_parameter
It says that

In your processor you should store audio parameter members for each of your parameters.

so I assume there’s nothing wrong in having that pointer…


#5

Sorry, I have to correct myself. The constructor does copy the array, so that was a red herring.


#6

I never said it was wrong to have a pointer. I only said that if you access that pointer after the list has deleted the AudioParameterChoice, then you are getting into troubles.

@mcjlnrtwcz: could you paste the call stack? That would help us figure out what is going on.