Don't leak memory in the blip buff wrapper if something goes bad

This commit is contained in:
nattthebear 2016-12-11 19:57:34 -05:00
parent 3cedc7479f
commit 871c16028a
1 changed files with 12 additions and 3 deletions

View File

@ -74,7 +74,7 @@ namespace BizHawk.Emulation.Common
public static extern void blip_delete(IntPtr context);
}
IntPtr context;
private IntPtr context;
public BlipBuffer(int sample_count)
{
@ -83,10 +83,19 @@ namespace BizHawk.Emulation.Common
throw new Exception("blip_new returned NULL!");
}
~BlipBuffer()
{
Dispose();
}
public void Dispose()
{
BlipBufDll.blip_delete(context);
context = IntPtr.Zero;
if (context != IntPtr.Zero)
{
BlipBufDll.blip_delete(context);
context = IntPtr.Zero;
GC.SuppressFinalize(this);
}
}
public void SetRates(double clock_rate, double sample_rate)