Skip to content

Commit

Permalink
Fix release of COM objects in DirectSoundOut.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
KF committed May 14, 2020
1 parent 1f2cbc7 commit 9356f58
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion NAudio/Wave/WaveOutputs/DirectSoundOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void InitializeDirectSound()
// Open DirectSound
lock (this.m_LockObject)
{
directSound = null;
Debug.Assert(directSound == null);
DirectSoundCreate(ref device, out directSound, IntPtr.Zero);

if (directSound != null)
Expand Down Expand Up @@ -553,13 +553,20 @@ private void StopPlayback()
CleanUpSecondaryBuffer();

secondaryBuffer.Stop();
Marshal.ReleaseComObject(secondaryBuffer);
secondaryBuffer = null;
}
if (primarySoundBuffer != null)
{
primarySoundBuffer.Stop();
Marshal.ReleaseComObject(primarySoundBuffer);
primarySoundBuffer = null;
}
if (directSound != null)
{
Marshal.ReleaseComObject(directSound);
directSound = null;
}
}
}

Expand Down

0 comments on commit 9356f58

Please sign in to comment.