JUCE Assertion failure in juce_AudioProcessorValueTreeState.cpp:315

Hello All,

I am trying to build a plugin project in projucer, using juce as a submodule.
Initially the project was set to build vst3, but I want it as standalone, so I changed project settings in projucer to include standalone as plugin format.

Now, I am getting the exception thrown when trying to build the project, which mentions
JUCE Assertion failure in juce_AudioProcessorValueTreeState.cpp:315

I did some searching, and found the related topic,

As discussed here, I added treeState.state = ValueTree("MyPlugin"); explicitly.

But still running into same exception,
and one thing to mention, I get this exception, only when building in standalone, vst3 builds successfully.

Any suggestion on how to tackle this issue?

Make sure this is done after all parameters are added. That’s what this jassert and the comment next to it is trying to tell you.

Also make sure to pick the right constructor for AudioProcessorValueTreeState.
If you want to add parameters in the AudioProcessor’s body, don’t use the constructor that gives the state a name and a ParameterLayout.

@daniel Thank you for quick response!
Can you explain more on picking up the correct constructor?

There is a lot of information in this thread, when the new method was introduced:


You can either:

// members
juce::UndoManager undo;
juce::AudioProcessorValueTreeState state { *this, &undo };
// constructor
state.createAndAddParameter (...);
state.state = juce::ValueTree("Parameters");


// members
juce::UndoManager undo;
juce::AudioProcessorValueTreeState state;
// free function
juce::AudioProcessorValueTreeState::ParameterLayout createParameters()
    juce::AudioProcessorValueTreeState::ParameterLayout layout;
    layout.add (std::make_unique<juce::AudioParameterFloat>(...);
    return layout;
// constructor:
  : state (*this, &undo, "Parameters", createParameters())

In the second version you cannot add parameters after the APVTS constructor, hence the jassert

@daniel Thank you !
Just to confirm, if I go with second option, I do not need to add parameters using
createAndAddParameter() in the MyProcessor() {} constructor…?

Yes, the parameters are already added by that createParameters() function.