InputStream from file question


#1

Why does this code cause an exception and how should it be done right?

[code]void MainComponent::loadWave()
{
File file(T(“c:\wav.wav”));
if (file.exists())
{
InputStream *stream=file.createInputStream();
if (stream)
{
WavAudioFormat format;
AudioFormatReader *reader=format.createReaderFor(stream, true);
if (reader)
{
wave=new AudioSampleBuffer(2,(int)reader->lengthInSamples);
wave->readFromAudioReader(reader, 0, (int)reader->lengthInSamples ,0, true, true);
waveformComponent->setWave(wave);

			deleteAndZero(reader);
		}
		
		deleteAndZero(stream);	// <--- EXCEPTION!!
	}
}

}[/code]


#2

The reader automatically deletes the stream that you give it, so just remove the line that deletes the stream and it’ll be fine.


#3

ofcourse, sorry for this stupid question :oops: