releaseResources read access violation

Hi,
I have the next problem.
My code:

	audioFileSource = nullptr;
		AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
		if (reader != nullptr) {
			audioFileSource = new AudioFormatReaderSource(reader, true);
			fileSource.stop();
			fileSource.setSource(nullptr);
			fileSource.setSource(audioFileSource, 32768, &readAheadThread, reader->sampleRate);
		}

When I set the source for the first time - everything is ok.
Then I change the source and receive the exception

Exception thrown: read access violation.
this->source.object.object-> was 0xFFFFFFFFFFFFFFEF.

in this method

void BufferingAudioSource::releaseResources()
{
    isPrepared = false;
    backgroundThread.removeTimeSliceClient (this);

    buffer.setSize (numberOfChannels, 0);

    // MSVC2015 seems to need this if statement to not generate a warning during linking.
    // As source is set in the constructor, there is no way that source could
    // ever equal this, but it seems to make MSVC2015 happy.
    if (source != this)
        source->releaseResources(); 
}

exception in this line: source->releaseResources();

Do you know what is wrong?

Thank you

use three backticks to format your code:
```
code
```

never heard of that VS2015 bug, but maybe you meant to check for nullptr instead?

if (source != nullptr)
    source->releaseResources(); 

that’s JUCE code, not his code.

Have you tried adding a breakpoint on the second fileSource.setSource(...) call and stepping in to see what is causing this->source.object.object to not have a valid address?

exception is before the second call of this method.
Exception is here: fileSource.setSource(nullptr);

logically there are three explanations IMHO:

  • you are setting a source as source to itself

  • this is nullptr
    (yes, you can call methods on a nullptr, it is undefined behaviour, but might complain later than you think)

  • you compiler is broken (most unlikely)

Also have a look, when you set sources, there is a parameter if the source shall be owned. You might have deleted a source twice accidentally:

BufferingAudioSource:

deleteSourceWhenDeleted: if true, then the input source object will be deleted when this object is deleted

I know, in case of the AudioTransportSource the BufferingAudioSource is an internal thing, but this applies to various AudioSources…

Good luck