NullPointer when adding Parameters to AudioProcessor


Hello guys,

I’m trying to follow the AudioProcessorGraph tutorial.

I’m failing at the point where I have to add the Parameters to the AudioProcessor. The following code is located in the PluginProcessor.cpp file in the constructor.

#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  AudioChannelSet::stereo(), true)
                       .withOutput ("Output", AudioChannelSet::stereo(), true)
, tree (*this, nullptr)
, mainProcessor  (new AudioProcessorGraph())
, muteInput      (new AudioParameterBool   ("mute",    "Mute Input", true))
, processorSlot1 (new AudioParameterChoice ("slot1",   "Slot1",     processorChoices, 0))
, processorSlot2 (new AudioParameterChoice ("slot2",   "Slot2",     processorChoices, 0))
    NormalisableRange<float> cutoffRange (20.0f, 20000.0f);
    NormalisableRange<float> resRange (1.0f, 5.0f);
    tree.createAndAddParameter("cutoffLp", "CutoffLp", "CutoffLp", cutoffRange, 600.0f, nullptr, nullptr);
    tree.createAndAddParameter("resonanceLp", "ResonanceLp", "ResonanceLp", resRange, 1.0f, nullptr, nullptr);
    tree.createAndAddParameter("cutoffHp", "CutoffHp", "CutoffHp", cutoffRange, 600.0f, nullptr, nullptr);
    tree.createAndAddParameter("resonanceHp", "ResonanceHp", "ResonanceHp", resRange, 1.0f, nullptr, nullptr);
    addParameter (muteInput);
    addParameter (processorSlot1);
    addParameter (processorSlot2);
    tree.state = ValueTree("filterTree");

I’m getting a NullPointer at the following location:

void AudioProcessorValueTreeState::updateParameterConnectionsToChildTrees()
    ScopedLock lock (valueTreeChanging);

    for (auto* param : processor.getParameters())
        jassert (dynamic_cast<Parameter*> (param) != nullptr); //Right here
        auto* p = static_cast<Parameter*> (param);

        p->setNewState (getOrCreateChildValueTree (p->paramID));

Is there anyone who has an idea why this happens?

Thanks guys


You should not mix the AudioParameterBool etc. classes with the AudioProcessorValueTree. Decide, which method to use, and crate all parameters that way.

My preference is the AudioProcessorValueTreeState, but that’s up to you.

The assert makes sure, you didn’t use a Parameter, that is not inheriting the AudioProcessorValueTreeState::Parameter class (it is private, so you can only use that with the createAndAddParameter method, that you used for cutoffLp etc.)

Hope that helps


Thank you very much!! :slight_smile: