I'm currently migrating my application to 64-bit and whenever I'm trying to dispose the WaveOut class, I'm getting an "AccessVoilationException" with the message "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Stacktrace:
at NAudio.Wave.WaveInterop.waveOutClose(IntPtr hWaveOut)
at NAudio.Wave.WaveOut.Dispose(Boolean disposing)
at NAudio.Wave.WaveOut.Dispose()
I've tested this with version 1.5 and 1.6 of NAudio, it only happens when I compile my application for 64-bit, 32-bit works fine.
Small codepiece where it happens:
if (wavePlayer != null)
{
this.wavePlayer.Stop();
this.wavePlayer.Dispose(); //AccessViolationException
}
Initialization of the WaveOut class:
this.wavePlayer = new WaveOut(WaveCallbackInfo.FunctionCallback());
I've also tried it with the new WaveOutEvent class in NAudio, but the problem persists.
Comments: With the WaveOut class, I strongly advise against using function callbacks, and using windows messages. In this scenario, you create the WaveOut object on your GUI thread, and all work should happen on the GUI thread (including filling the buffer). With WaveOutEvent, a separate background thread is created for the purposes of filling the buffers up. However, if possible, it marshalls the PlaybackStopped event to the GUI thread.
Stacktrace:
at NAudio.Wave.WaveInterop.waveOutClose(IntPtr hWaveOut)
at NAudio.Wave.WaveOut.Dispose(Boolean disposing)
at NAudio.Wave.WaveOut.Dispose()
I've tested this with version 1.5 and 1.6 of NAudio, it only happens when I compile my application for 64-bit, 32-bit works fine.
Small codepiece where it happens:
if (wavePlayer != null)
{
this.wavePlayer.Stop();
this.wavePlayer.Dispose(); //AccessViolationException
}
Initialization of the WaveOut class:
this.wavePlayer = new WaveOut(WaveCallbackInfo.FunctionCallback());
I've also tried it with the new WaveOutEvent class in NAudio, but the problem persists.
Comments: With the WaveOut class, I strongly advise against using function callbacks, and using windows messages. In this scenario, you create the WaveOut object on your GUI thread, and all work should happen on the GUI thread (including filling the buffer). With WaveOutEvent, a separate background thread is created for the purposes of filling the buffers up. However, if possible, it marshalls the PlaybackStopped event to the GUI thread.