fix AudioDevice crash on shutdown
parent
e73c7ede55
commit
81cd397013
|
@ -42,6 +42,7 @@ namespace MoonWorks.Audio
|
||||||
private AutoResetEvent WakeSignal;
|
private AutoResetEvent WakeSignal;
|
||||||
internal readonly object StateLock = new object();
|
internal readonly object StateLock = new object();
|
||||||
|
|
||||||
|
private bool Running;
|
||||||
private bool IsDisposed;
|
private bool IsDisposed;
|
||||||
|
|
||||||
public unsafe AudioDevice()
|
public unsafe AudioDevice()
|
||||||
|
@ -130,13 +131,15 @@ namespace MoonWorks.Audio
|
||||||
Thread.IsBackground = true;
|
Thread.IsBackground = true;
|
||||||
Thread.Start();
|
Thread.Start();
|
||||||
|
|
||||||
|
Running = true;
|
||||||
|
|
||||||
TickStopwatch.Start();
|
TickStopwatch.Start();
|
||||||
previousTickTime = 0;
|
previousTickTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThreadMain()
|
private void ThreadMain()
|
||||||
{
|
{
|
||||||
while (!IsDisposed)
|
while (Running)
|
||||||
{
|
{
|
||||||
lock (StateLock)
|
lock (StateLock)
|
||||||
{
|
{
|
||||||
|
@ -278,8 +281,9 @@ namespace MoonWorks.Audio
|
||||||
{
|
{
|
||||||
if (!IsDisposed)
|
if (!IsDisposed)
|
||||||
{
|
{
|
||||||
lock (StateLock)
|
Running = false;
|
||||||
{
|
Thread.Join();
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
foreach (var weakReference in resources)
|
foreach (var weakReference in resources)
|
||||||
|
@ -300,7 +304,6 @@ namespace MoonWorks.Audio
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
~AudioDevice()
|
~AudioDevice()
|
||||||
{
|
{
|
||||||
|
|
|
@ -311,6 +311,18 @@ namespace MoonWorks.Audio
|
||||||
|
|
||||||
protected override unsafe void Destroy()
|
protected override unsafe void Destroy()
|
||||||
{
|
{
|
||||||
|
foreach (var instance in UsedInstances)
|
||||||
|
{
|
||||||
|
instance.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var instance in AvailableInstances)
|
||||||
|
{
|
||||||
|
instance.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
AvailableInstances.Clear();
|
||||||
|
|
||||||
if (OwnsBuffer)
|
if (OwnsBuffer)
|
||||||
{
|
{
|
||||||
NativeMemory.Free((void*) Handle.pAudioData);
|
NativeMemory.Free((void*) Handle.pAudioData);
|
||||||
|
|
|
@ -86,12 +86,21 @@ namespace MoonWorks
|
||||||
Tick();
|
Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogInfo("Starting shutdown sequence...");
|
||||||
|
|
||||||
|
Logger.LogInfo("Cleaning up game...");
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
|
Logger.LogInfo("Closing audio thread...");
|
||||||
AudioDevice.Dispose();
|
AudioDevice.Dispose();
|
||||||
|
|
||||||
|
Logger.LogInfo("Unclaiming window...");
|
||||||
GraphicsDevice.UnclaimWindow(MainWindow);
|
GraphicsDevice.UnclaimWindow(MainWindow);
|
||||||
|
|
||||||
|
Logger.LogInfo("Disposing window...");
|
||||||
MainWindow.Dispose();
|
MainWindow.Dispose();
|
||||||
|
|
||||||
|
Logger.LogInfo("Disposing graphics device...");
|
||||||
GraphicsDevice.Dispose();
|
GraphicsDevice.Dispose();
|
||||||
|
|
||||||
SDL.SDL_Quit();
|
SDL.SDL_Quit();
|
||||||
|
|
Loading…
Reference in New Issue