Read access violation _Mem was nullptr

Hi, I’m a complete beginner to JUCE. I’ve been following along to this video right here: Learn Modern C++ by Building an Audio Plugin (w/ JUCE Framework) - Full Course - YouTube

Recently I’ve ran into an error that has me completely stumped. Whenever I try to debug I’m met with the error "Exception thrown: read access violation. _Mem was nullptr.

I went to the place where the call stack showed the exception happening which is right here. I’ve checked but no matter what I seem to do, nothing will fix it.

Does anyone know what might be causing this? Thanks

Here’s the image of the main error

this is nullptr

You’re using an invalid object

Rail

Hey, I am having the exact same issue, did you ever figure it out?

Same here, everything been going fine then this suddenly pops up for as far as I can tell, no apparent reason?

I’m using an ‘Invalid Object’, which one?

Why does Visual Studio show No Issues but then it throws this up when you try and debug?

Because this is a runtime issue, not a compile time issue.

And it’s not for “No apparent reason”, you have a bug. You need to learn how to debug, so you can find and fix your bug.

OK yes that makes sense, because even the Plugin Window pops up for a second then disappears, that’s a clue!

I need to learn to debug, yep I do :frowning:

2 Likes

let me know if you figure it out, ill do the same :grin:

NoahW29, I did figure it out, it was a Copy & Paste error, Doh!

Inside the PluginProcessor.cpp and the getChainSettings function I had:

settings.peakBypassed = apvts.getRawParameterValue(“Peak Bypassed”)->load() > 0.5f;

But inside the createParameterLayout function I had:

layout.add(std::make_uniquejuce::AudioParameterBool(“PeakCut Bypassed”, “PeakCut Bypassed”, false));

Not sure why the Compiler didn’t pick that up, and the Error made no sense to me, I found it by just back tracking and commenting out line by line till it didn’t crash anymore!

1 Like

Two words of advice here:

Don’t copy&paste strings (actually don’t copy&paste at all, but that is a different story).
Instead define the paramIDs as constexpr or static strings:

class MyAudioProcessor // ...
{
    static constexpr auto cutoffID = "PeakCut Bypassed";
}
// ...
{
    settings.peakBypassed = apvts.getRawParameterValue (MyAudioProcessor::cutoffID)->load() > 0.5f;
}

The compiler doesn’t read string literals at all. Those will only be found at runtime.

Second advice:
Don’t use the getRawParameterValue() in the processing, as it is a slow method.
Instead keep a pointer to the properly casted version. Of course you need to change the ChainSettings a bit, because at the moment that is copied and destroyed a lot.
If the getChainSettings() method was a method of the processor, you could store the pointers in the processor.