fix audio thread race condition on StaticAudio.GetInstance
parent
36ddb03d8f
commit
74ae295036
|
@ -271,24 +271,43 @@ namespace MoonWorks.Audio
|
||||||
/// NOTE: If AutoFree is false, you will have to call StaticSoundInstance.Free() yourself or leak the instance!
|
/// NOTE: If AutoFree is false, you will have to call StaticSoundInstance.Free() yourself or leak the instance!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StaticSoundInstance GetInstance(bool autoFree = true)
|
public StaticSoundInstance GetInstance(bool autoFree = true)
|
||||||
|
{
|
||||||
|
StaticSoundInstance instance;
|
||||||
|
|
||||||
|
lock (AvailableInstances)
|
||||||
{
|
{
|
||||||
if (AvailableInstances.Count == 0)
|
if (AvailableInstances.Count == 0)
|
||||||
{
|
{
|
||||||
AvailableInstances.Push(new StaticSoundInstance(Device, this));
|
AvailableInstances.Push(new StaticSoundInstance(Device, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance = AvailableInstances.Pop();
|
instance = AvailableInstances.Pop();
|
||||||
|
}
|
||||||
|
|
||||||
instance.AutoFree = autoFree;
|
instance.AutoFree = autoFree;
|
||||||
|
|
||||||
|
lock (UsedInstances)
|
||||||
|
{
|
||||||
UsedInstances.Add(instance);
|
UsedInstances.Add(instance);
|
||||||
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void FreeInstance(StaticSoundInstance instance)
|
internal void FreeInstance(StaticSoundInstance instance)
|
||||||
{
|
{
|
||||||
instance.Reset();
|
instance.Reset();
|
||||||
|
|
||||||
|
lock (UsedInstances)
|
||||||
|
{
|
||||||
UsedInstances.Remove(instance);
|
UsedInstances.Remove(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (AvailableInstances)
|
||||||
|
{
|
||||||
AvailableInstances.Push(instance);
|
AvailableInstances.Push(instance);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override unsafe void Destroy()
|
protected override unsafe void Destroy()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue