PlayingSoundFiles tutorial - setSource method on the AudioTransportSource for seconds time leads to EXC_BAD_ACCESS


#1

Hello,

I had an issue with the tutorial "Playing Sound Files" tutorial  ( http://learn.juce.com/doc/tutorial_playing_sound_files.php).
The tutorial takes you through a basic sound player which I was able to compile and run from XCode.

The issue I encountered happens when you try to open a new file after you have opened a file once already. If I try to open a different file by clicking for the second time on the "Open" TextButton, selecting a file and clicking Open in the dialog I get an error that is caused by the line 

transportSource.setSource (readerSource, 0, nullptr, reader->sampleRate);

in 

    void openButtonClicked(){
        FileChooser chooser ("Select a Wave file to play...",File::nonexistent,"*.wav");                                        
        if (chooser.browseForFileToOpen())
        {
            File file (chooser.getResult());
            AudioFormatReader* reader = formatManager.createReaderFor (file);
            if (reader != nullptr)
            {
                readerSource = new AudioFormatReaderSource (reader, true);
                transportSource.setSource (readerSource, 0, nullptr, reader->sampleRate);
                playButton.setEnabled (true);                                             // [13]
            }

All I could understand is that it seems like it fails to find an AudioSource to delete at some point in the setSource method, in juce_ResamplingAudioSource.cpp at:

void ResamplingAudioSource::releaseResources()
{
    input->releaseResources();
    buffer.setSize (numChannels, 0);
}

Can anyone tell me what's the cause and how to fix it? Any help will be deeply appreciated!


AudioTransportSource setSource not working when it is run a second time
#2

Bump. I am having the exact same issue in something related. Perhaps there is a better way to play audio files?

If someone could help me out that would be great