avoid race condition on StreamingSound.Dispose

cosmonaut 2023-12-13 13:58:55 -08:00
parent 97dd112e7a
commit 52e7384e45
1 changed files with 8 additions and 5 deletions

View File

@ -150,13 +150,16 @@ namespace MoonWorks.Audio
{ {
if (!IsDisposed) if (!IsDisposed)
{ {
Stop(); lock (StateLock)
for (int i = 0; i < BUFFER_COUNT; i += 1)
{ {
if (buffers[i] != IntPtr.Zero) Stop();
for (int i = 0; i < BUFFER_COUNT; i += 1)
{ {
NativeMemory.Free((void*) buffers[i]); if (buffers[i] != IntPtr.Zero)
{
NativeMemory.Free((void*) buffers[i]);
}
} }
} }
} }