This project has moved and is read-only. For the latest updates, please go here.

WaveFormatConversionStream class attempting to reference a null pointer...


Greetings all,

I am using 1.7 to play around with WaveOut Audio using the Event callback mechanism.

Whenever I exit out of the demo while audio is playing Visual Studio is raising an unhandled exception error. When I look further into it I have found that the WaveFormatConversionStream class is attempting to access either "sourceStream" or "conversionStream" and both of these members are null. I think it has to do with closing the demo window (using the red "X" in the upper right corner) while audio is playing because if I stop the audio first (click on the square block) then there are no exceptions raised. I am going to guess that these exceptions go unnoticed if you are not running under Visual Studio.

To reproduce:
  1. Load the NAudio.sln in VS2010.
  2. Set the NAudioDemo project as the Startup Project.
  3. Be building and running in "Debug" mode.
  4. Hit "F5" to kick things off.
  5. Select "Audio File Playback" and press Load.
  6. Select "Event" "Callback Mechanism:" and start playing a .wav file.
  7. Click on the red "X" in the upper right hand corner to close NAudio Demo.


markheath wrote Feb 19, 2014 at 11:08 PM

good spot. The AudioPlaybackPanel should not really be trying to reposition the file after it has been disposed. But I could add some protection into AudioFilePlayer as well

mguyott wrote Feb 20, 2014 at 3:51 PM

Sounds good Mark. I would think that the WaveFormatConversionStream class itself should check for this condition and either take alternative action or raise an explicit exception. Allowing the null pointer access exception seems like the wrong thing to do to me.

Just my two cents, your mileage may vary.

Thanks again for letting me know what was going on.


markheath wrote Feb 27, 2014 at 10:27 PM

I've fixed the demo app. Probably classes like WaveFormatConversionStream and AudioFIleReader should throw ObjectDisposedException to make this obvious if you call methods after calling Dispose