Application Error with setParameterNotifyingHost


#1

Hey everyone, I’m slowly getting up to speed with Juce and DSP, so I apologize if what I may be doing is a hack but essentially, I’m following along the Audio Plugin demo, except right now I’m only implementing gain being changed, as if I want a VST that just adjusts volume (for now). Now the timer callbacks seem to work no problem however my VST crashes when I go to move the slider that triggers:

if (slider == slider1)
	{
		getProcessor()->setParameterNotifyingHost (JuceAudioTestAudioProcessor::gainParam, (float)slider1->getValue());
	}

I get an application error (in Reaper) saying "The instruction at “0x03b543d0” referenced memory at “0x00000004”. The memory could not be “read”.

And it’s the above call that triggers it, my code in my Processor looks like this:

[code]void JuceAudioTestAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
// This is the place where you’d normally do the guts of your plugin’s
// audio processing…
for (int channel = 0; channel < getNumInputChannels(); ++channel)
{
float* channelData = buffer.getSampleData (channel);

    // ..do something to the data...
	buffer.applyGain (channel, 0, buffer.getNumSamples(), gain);
}

// In case we have more outputs than inputs, we'll clear any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
{
    buffer.clear (i, 0, buffer.getNumSamples());
}

}[/code]

I only have a gainParam and numParams, and in addition I’m using the float variable “gain” as the variable name just like in the demo.
Now when I debug I get:
"Unhandled exception at 0x03b543d0 (Juce Audio test.dll) in reaper.exe: 0xC0000005: Access violation reading location 0x00000004."
and it breaks at this code:

void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
{
    jassert (isPositiveAndBelow (parameterIndex, getNumParameters()));

    for (int i = listeners.size(); --i >= 0;)
    {
        AudioProcessorListener* l;

        {
            const ScopedLock sl (listenerLock);
            l = listeners [i];
        }

        if (l != 0)
            l->audioProcessorParameterChanged (this, parameterIndex, newValue);   // IT POINTS TO THIS LINE 
    }
}

Now I’m not entirely sure what’s going on, and I don’t know if somehow the VST I’m trying to design maybe isn’t somehow taking in input from the DAW or something, as it’s built off the Juce Audio Demo which is a synth. I could be out to lunch somewhere but I’ve been trying and trying with this and no luck. Any help would be appreciated! Thanks!


#2

I’d also like to add I built the plugin using the Jucer, with the Audio Plugin template.


#3

Anyone? I’m also using a timer and a timerCallback function which looks like this:

void JuceAudioTestAudioProcessorEditor::timerCallback()
{
	JuceAudioTestAudioProcessor* ourProcessor = getProcessor();

	// will need to put code here to grab values from filter
	slider1->setValue (ourProcessor->gain, true, false);
}

I’m using this to check for any changes, I’m assuming this is ok, for an effect. I’ve also omitted the use of any AudioPlayHead code as it seemed unnecessary for something like this. Any help would be appreciated, I just feel like I need to get this simple gain program working and once I do, I’ll be able to start throwing my dsp in there. Thanks again guys. Any help at all would be appreciated.


#4

First, update to the latest version of juce - I can’t help with problems that are based on an old version of the codebase.

It’s not at all clear from your snippet what’s going on, you need to spend some quality time with your debugger and actually watch what’s happening. But it’s most likely that you’re just using a null or dangling pointer somewhere.


#5

Ok thanks, I had no idea it was on an older version. I have the latest and I’m going to redo it and be much more careful of what I’m doing, and get post back.

Also I apologize for being a total beginner with this, but what is the best way to go about debugging a VST? I just load it in Reaper and when it crashes I select “cancel” to load up VS2010 and debug it (that’s where I got the error I posted), is there a different/better way to do this, or is that the right way? Thanks again.


#6

The other way round is the right way to do it. You need to first load and compile the project in VS2010, in debug mode. Set the executable to Reaper in VS’s debug menu. Then, hit F5 to start debugging.


#7

Thanks for the tip, but now I’m absolutely about to rip my hair out and gouge out my eyes, as I get this error all the time now! Even when rebuilding and trying to make a simple project again, I get this red error in reaper when I load a VST:

Microsoft Visual C++ Debug Library as the header but it basically says this:

Now at this point I can’t his retry to debug as it’s locked up, and I’ve changed my debug exe back to $(TargetPath) and tried launching the VST in Reaper, and I get this error still. I thought this may be to do with some unallocated memory or something so I started a new project, and I only messed with the editor settings, nothing in the processor, as I had before. When I load the VST as the default with “Hello World” it works fine, but as soon as I add a slider it goes to shit now, I’m going to show my code here just top show there’s nothing fishy going on:

PluginEditor.h:

/*
  ==============================================================================

    This file was auto-generated by the Jucer!

    It contains the basic startup code for a Juce application.

  ==============================================================================
*/

#ifndef __PLUGINEDITOR_H_E85AA9C5__
#define __PLUGINEDITOR_H_E85AA9C5__

#include "../JuceLibraryCode/JuceHeader.h"
#include "../JuceLibraryCode/JucePluginCharacteristics.h"
#include "PluginProcessor.h"


//==============================================================================
/**
*/
class JuceTestAudioProcessorEditor  : public AudioProcessorEditor,
	public Slider::Listener
{
public:
    JuceTestAudioProcessorEditor (JuceTestAudioProcessor* ownerFilter);
    ~JuceTestAudioProcessorEditor();

    //==============================================================================
    // This is just a standard Juce paint method...
    void paint (Graphics& g);

	//==============================================================================
	void sliderValueChanged (Slider* slider);

private:
	Slider gainSlider;
};


#endif  // __PLUGINEDITOR_H_E85AA9C5__

PluginEditor.cpp

/*
  ==============================================================================

    This file was auto-generated by the Jucer!

    It contains the basic startup code for a Juce application.

  ==============================================================================
*/

#include "PluginProcessor.h"
#include "PluginEditor.h"


//==============================================================================
JuceTestAudioProcessorEditor::JuceTestAudioProcessorEditor (JuceTestAudioProcessor* ownerFilter)
    : AudioProcessorEditor (ownerFilter)
{
    // This is where our plugin's editor size is set.
    setSize (400, 400);

	// Sliders...
	gainSlider.setName ("gain");
	gainSlider.setSliderStyle (Slider::Rotary);
	gainSlider.setTextBoxStyle (Slider::TextBoxAbove, true, 100, 45);
	gainSlider.setBounds (100, 75, 200, 200);
	addChildComponent (&gainSlider, -1);
	gainSlider.addListener (this);

	addAndMakeVisible (&gainSlider);

}

JuceTestAudioProcessorEditor::~JuceTestAudioProcessorEditor()
{
	deleteAllChildren ();
}

//==============================================================================
void JuceTestAudioProcessorEditor::paint (Graphics& g)
{
	g.fillAll (Colours::peru);
    g.setColour (Colours::black);
    g.setFont (15.0f);
	/*
    g.drawFittedText ("Hello World!",
                      0, 0, getWidth(), getHeight(),
                      Justification::centred, 1);
	*/
}

void JuceTestAudioProcessorEditor::sliderValueChanged (Slider* slider)
{
}

I hope maybe someone can help? I really have no idea why this is happening now and I’m beginning to get at my wits end…after hours and hours of trying to make it work. Sorry to annoy with these matters.


#8

Doh! Careless use of deleteAllChildren() costs lives! Calling delete on your gainSlider object isn’t a particularly smart move.


#9

…and that would be it!

Thanks. Gain and everything is working fine now!

I guess it’s not really necessary to release a component then…? (non-pointer)

Typical programmer’s fatigue, hours and hours of frustration boiled down to one line of code!


#10

They’re just c++ objects - all the normal rules apply.