HeavenWu / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

SourceVoice.Dispose AccessViolation following inconsistent use of SetChannelVolumes #741

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Steps To Reproduce:
1. First, get a monaural .wav file.
2. Play the .wav in the ordinary manner, but call 'SetChannelVolumes(2, new 
float{0.5f,0.5f})' on the SourceVoice prior to submitting the buffer (see 
example PlayWaveStream method).
3. Observe subsequent crash when Disposing the SourceVoice.

Expected Behavior: So, this was totally my bug! I was trying to allow panning 
of arbitrary sounds (some of which might be monaural), but this is clearly not 
the way to go about it. The request is that SlimDX help me out by throwing an 
exception on calling 'SetChannelVolumes' with the invalid channel count, rather 
than crashing somewhere downstream. 

Version: SlimDX (June 2010)

//----------------- PlayWaveStream method -------------------//

    private void PlayWaveStream( WaveStream i_ws )
    {
      AudioBuffer buffer = new AudioBuffer();
      buffer.AudioData = i_ws;
      buffer.AudioBytes = (int)i_ws.Length;
      buffer.Flags = BufferFlags.EndOfStream;

      SourceVoice sourceVoice = new SourceVoice( m_device, i_ws.Format );

      //debug: deliberately hoping to stimulate crash
      sourceVoice.SetChannelVolumes(2, new float[]{1.0f,0.1f});

      sourceVoice.SubmitSourceBuffer( buffer );
      sourceVoice.Start();      

      while ( sourceVoice.State.BuffersQueued > 0 ) { Thread.Sleep(10); }      

      buffer.Dispose();
      sourceVoice.Dispose();
    }

//-------------------------- crash callstack -----------------//

Callstack:

C:\Users\blah\slimdx\xaudio2_01\xaudio2_test\bin\Debug>xaudio2_test.exe 
MusicMono.wav
--------------------------------------
bytes per second: 88200
bits per sample: 16
block alignment: 2
channels: 1
Samples Per Second : 44100
FormatTag : Pcm
--------------------------------------

Unhandled Exception: System.AccessViolationException: Attempted to read or write
 protected memory. This is often an indication that other memory is corrupt.
   at SlimDX.XAudio2.SourceVoice.~SourceVoice()
   at SlimDX.XAudio2.SourceVoice.Dispose(Boolean )
   at SlimDX.XAudio2.SourceVoice.Dispose()
   at xaudio2_test.SoundPlayer.PlayWaveStream(WaveStream i_ws) in C:\Users\blah\slimdx\xaudio2_01\xaudio2_test\SoundPlayer.cs:line 332
   at xaudio2_test.SoundPlayer.PlaySound(String i_strWAV) in C:\Users\blah\slimdx\xaudio2_01\xaudio2_test\SoundPlayer.cs:line 43
   at xaudio2_test.Program.Main(String[] args) in C:\Users\dwoodruff\blah\slimdx\xaudio2_01\xaudio2_test\Program.cs:line 25

Original issue reported on code.google.com by davidmwo...@gmail.com on 21 Nov 2010 at 11:57

GoogleCodeExporter commented 8 years ago
Can we actually do the detection asked for here?

Original comment by josh.petrie on 4 Dec 2010 at 9:53

GoogleCodeExporter commented 8 years ago
I took a look around, and unfortunately there's no way for us to know the 
number of output channels, so we can't check this for you. XAudio2 really 
should do better checking than just crashing randomly, but we can't really help 
that here.

Original comment by Mike.Popoloski on 12 Dec 2010 at 4:27

GoogleCodeExporter commented 8 years ago
ok, thanks for looking at it. The bug may still help anyone else who runs into 
the same issue. 

Original comment by davidmwo...@gmail.com on 12 Dec 2010 at 8:59