SOLVED: VST crashes when hitting play in host after loading audio file


#1

I am loading an audio file into a TransportAudioSource and hooking it up to the ProcessBlock. The plugin works perfectly fine while the host is stopped. As soon as I press play, the host crashes (or the bridge). Tested in Reaper and FL Studio. 

Before I load the audio file, the host has no problem playing. It only crashes once I've loaded a file. 

I tried commenting out everything in my process block but it still crashes. Pretty stumped. 

What happens to the plugin when the host starts playing? What's the difference?

 

In PluginProcessor.h:

//...

private:
    AudioFormatReader* reader;
    ScopedPointer<AudioFormatReaderSource> readerSource;
    AudioSampleBuffer sampleSource;
    TimeSliceThread transportThread;

In PluginProcessor.cpp:

void MyAudioProcessor::loadFile(File file){
    loadedFile = file;
    transportSource.stop();
    transportSource.setSource(nullptr);
    readerSource = nullptr;
    reader = nullptr;

    reader = formatManager.createReaderFor(loadedFile);

    if (reader != 0){
        readerSource = new AudioFormatReaderSource(reader, false);

        transportThread.startThread();
        transportSource.setSource(readerSource, 0, &transportThread, 0.0, 2);
    }
}

I've experimented with different ReadAheadBuffer sizes. I also tried using transportSource.setSource() without giving it a thread. No dice.

If I debug the crash it says

"Unhandled exception at 0x000007FED559BB58 (MyPlugin.dll) in reaper.exe:
0xC0000005: Access violation reading location 0XFFFFFFFFFFFFFFFF"

The call stack stops at AudioTransportSource::getNextReadPosition() Line 198

 

Any thoughts?


Add file in Audio Plugin Juce
#2

Figured it out! I had readerSource = nullptr in releaseResources(). Don't do that.