Hi, I’m new to JUCE and have been trying to implement an automation parameter to a gain slider, following a tutorial from The Audio Programmer. Ableton does show the parameter.
However, creating a SliderAttachment prevents the VST from opening at all. VS throws no errors so I can’t tell where the issue is. I’ve been trying to debug for about 5 hours and can’t find any similar posts to help.
Here is some code in PluginEditor.cpp:
SimpleGainSliderAudioProcessorEditor::SimpleGainSliderAudioProcessorEditor (SimpleGainSliderAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
setSize (200, 400);
gainSlider.setSliderStyle(juce::Slider::SliderStyle::LinearVertical);
gainSlider.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 100, 25);
gainSlider.setRange(-48.0, 0.0);
gainSlider.setValue(-1.0);
gainSlider.addListener(this);
addAndMakeVisible(gainSlider);
//create sliderAttachment linking processors's treeState to gainSlider
sliderAttach = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.treeState, GAIN_ID, gainSlider);
}
Let me know if there is other code you need to check.
Commenting out the line where sliderAttach is declared fixes the crash, but I can’t figure out what is wrong with this line. VS throws no errors.
Help is appreciated, over the last 5 hours I’ve tried about every avenue there is other than creating a forum post.
In the debugger this will halt execution if the parameter doesn’t exist.
N.B. you can simplify your code by a) setting up the sliderStyle in the header and b) setRange and setValue will be overwritten by the attachment, so you can remove those lines as well:
Is it to do with null pointers or datatypes or something? This is the first time I’m trying to implement parameters and I can’t understand why it’s being so difficult.
This is the call stack for the error:
simpleGainSlider.exe!std::_Func_class<juce::String,float>::operator()(float <_Args_0>) Line 917
at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\functional(917)
The call stack should be a list of functions, not just one position.
The error is indeed way to far inside the details, so it is hard to figure out what went wrong.
Click the call stack one by one out of the stack (I always hum Talking Heads when debugging: “how did I get here”).
Things to look for:
is this a legit address?
is there a mathematical problem?
what memory do I access, is that legit?
When you are stuck, best post the whole call stack with line numbers
treeState.createAndAddParameter() is deprecated and parameters shouldn’t be added this way. I knew this but assumed it should still be functional. Don’t use this method or any tutorials that use it. Parameters are now declared within the APVTS constructor.