VST Critical error when i create new attachment for sliders



driveAttachment = new AudioProcessorValueTreeState::SliderAttachment(p.getState(), “drive”, driveKnob);

^ This line of code causes my vst to produce a critical error. I am following this tutorial and I am stuck at the 40-minute mark and have copied everything so far exactly. https://www.youtube.com/watch?v=iNCR5flSuDs.
I have no past experience with c++ so you will have to explain where all the stuff goes. is there an alternative or a fix I can do to get this to work. thanks


What’s a “critical error”? What does the debugger show?


Thanks for the response, idk what you mean by the debugger but there are no build errors and it is flstudio that shows critical error when i load the plugin with that line of code


Unfortunately “no build errors” means nothing in C++. The code could be completely buggy and the compiler will still compile it. (In some cases enabling compiler warnings as errors may expose some issues, though.)

The debugger is a very important development tool, you should immediately get yourself familiar with it. When you run your code under the debugger, it can catch runtime errors and get you at the place in the code where the error happened, among other things.

I don’t want to watch the video and copy the code from that manually, can you post your project code somewhere already written out? (Why didn’t the Youtube video author provide the source code anyway…? :man_facepalming: )


Thanks for the help yeah i cant find out anything online about a juce debugger and yeah there was no source code available :(.

Plugineditor.cpp -

addAndMakeVisible(driveKnob = new Slider("Drive"));
driveKnob->setRange(0, 50);
setSize(800, 400);
driveAttachment = new AudioProcessorValueTreeState::SliderAttachment(p.getState(), “drive”, driveKnob);

AudioProcessorValueTreeState& NewProjectAudioProcessor::getState() { return *state; }


NewProjectAudioProcessor &processor;`ScopedPointer<Slider> driveKnob;
ScopedPointer<AudioProcessorValueTreeState::SliderAttachment> driveAttachment;

NewProjectAudioProcessor &processor;`

PluginProcessor.h -
public: AudioProcessorValueTreeState& getState(); private: ScopedPointer<AudioProcessorValueTreeState> state; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NewProjectAudioProcessor) };

that basically sums up the code that I have added to the default juce audio plugin template. I am building a vst2 plugin in 64 bit using the latest Steinberg libraries.


edit to the original post i meant the code was driveAttachment = new AudioProcessorValueTreeState::SliderAttachment(p.getState(), “drive”, *driveKnob);


edit: works now. idk what i did


If you solved the problem could you try to explain quickly what you did to fix it? Other users with the same issue who stumble upon this would find it useful.

Also there’s a few things in the code examples you gave I would change as such:

Firstly, ScopedPointers are depreciated so you want to replace them with std::unique_ptrs:
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> driveAttachment;
std::unique_ptr<AudioProcessorValuetreeState> state;

Second, from the code you’ve given there’s no reason to have your Slider as a pointer. You can just make it a normal object (unless you need it to be a pointer elsewhere in which case make it a unique_ptr also).

You have processor declared twice… Maybe this was just a typo but make sure you only have one.

Now with these changes, in Plugineditor.cpp:

PluginEditor(...) : driveKnob("Drive")
    driveKnob.setTextBoxStyle(Slider::NoTextBox, false, 100, 100);
    driveKnob.setRange(0, 50);
    driveAttachment.reset(new AudioProcessorValueTreeState::SliderAttachment(p.getState(), "drive", *driveKnob));

    setSize(800, 400);


alright thanks, i would like to help but i dont have a clue what i did


i am having some issues changing it over to a unique pointer, i cant link it to the parameter name “drive”, where you have done this: PluginEditor(…) : driveKnob(“Drive”)

this is my code:

NewProjectAudioProcessorEditor::NewProjectAudioProcessorEditor (NewProjectAudioProcessor& p) : AudioProcessorEditor (&p), processor (p) {

addAndMakeVisible(driveKnob = new Slider("Drive"));
driveKnob->setTextBoxStyle(Slider::NoTextBox, false, 100, 100);


I guess your problem is, that there is no implicit overload to the pointer operator. Instead you will have to write:

driveKnob = new Slider("Drive");
addAndMakeVisible (driveKnob.get());

It is possible in one line, but personally I find that unreadable. One line, one instruction is my mantra.

addAndMakeVisible ((driveKnob = new Slider("Drive")).get());


The PluginEditor(…) : driveKnob(“Drive”) syntax will only work for non-pointer types so if driveKnob is a std::unique_ptr you will need to remove this line and initialize your managed slider object inside the constructor body.

Also driveKnob = new Slider("Drive"); doesn’t work for unique_ptr. You must use driveKnob.reset(new Slider("Drive")); instead.


hi, sorry for late reply, that works. i have annother problem now where my plugin crashes when i minimize or close it inside of the daw. also it makes no differance to the sound


Can you please always add the stack trace, when you experience a crash?
There are just too many things that could have gone wrong, especially since nobody knows your code.


i will try find out how to get that as i have no idea what that is. thanks


Learn to use the debugger.


i looked online how to use that but couldnt find any info. is there a guide somewhere? thanks


I googled “c++ debugging” and got 11 million results.

Seriously, you’re going to be given a hard time by any kind of coding community unless you make the effort to learn the basic tools!


This is not JUCE-specific but you should be able to get some understanding of the procedure in Visual Studio :


Thanks, i understand how to do that now but now i just have to understand how to use it to find the issue haha