VST Critical error when i create new attachment for sliders

windows

#1

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


#2

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


#3

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


#4

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: )


#5

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->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
driveKnob->setTextBoxStyle(Slider::NoTextBox,false,100,100);
driveKnob->setRange(0, 50);
setSize(800, 400);
driveAttachment = new AudioProcessorValueTreeState::SliderAttachment(p.getState(), “drive”, driveKnob);

PluginProcessor.cpp-
AudioProcessorValueTreeState& NewProjectAudioProcessor::getState() { return *state; }

PluginEditor.h-

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.


#6

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


#7

edit: works now. idk what i did


#8

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:
PluginEditor.h:
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> driveAttachment;
PluginProcessor.h:
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")
{
    ...
    addAndMakeVisible(driveKnob);
    driveKnob.setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
    driveKnob.setTextBoxStyle(Slider::NoTextBox, false, 100, 100);
    driveKnob.setRange(0, 50);
    
    driveAttachment.reset(new AudioProcessorValueTreeState::SliderAttachment(p.getState(), "drive", *driveKnob));

    setSize(800, 400);
    ...
}

#9

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


#10

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->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
driveKnob->setTextBoxStyle(Slider::NoTextBox, false, 100, 100);

#11

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());

#12

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.


#13

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


#14

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.


#15

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


#16

Learn to use the debugger.


#18

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


#19

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!


#20

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


#21

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