stop updating audio on dispose
parent
a9dd3dc13f
commit
97dd112e7a
|
@ -25,7 +25,7 @@ namespace MoonWorks.Audio
|
||||||
public float DopplerScale = 1f;
|
public float DopplerScale = 1f;
|
||||||
public float SpeedOfSound = 343.5f;
|
public float SpeedOfSound = 343.5f;
|
||||||
|
|
||||||
private readonly HashSet<GCHandle> resources = new HashSet<GCHandle>();
|
private readonly HashSet<GCHandle> resourceHandles = new HashSet<GCHandle>();
|
||||||
private readonly HashSet<UpdatingSourceVoice> updatingSourceVoices = new HashSet<UpdatingSourceVoice>();
|
private readonly HashSet<UpdatingSourceVoice> updatingSourceVoices = new HashSet<UpdatingSourceVoice>();
|
||||||
|
|
||||||
private AudioTweenManager AudioTweenManager;
|
private AudioTweenManager AudioTweenManager;
|
||||||
|
@ -265,7 +265,7 @@ namespace MoonWorks.Audio
|
||||||
{
|
{
|
||||||
lock (StateLock)
|
lock (StateLock)
|
||||||
{
|
{
|
||||||
resources.Add(resourceReference);
|
resourceHandles.Add(resourceReference);
|
||||||
|
|
||||||
if (resourceReference.Target is UpdatingSourceVoice updatableVoice)
|
if (resourceReference.Target is UpdatingSourceVoice updatableVoice)
|
||||||
{
|
{
|
||||||
|
@ -278,7 +278,12 @@ namespace MoonWorks.Audio
|
||||||
{
|
{
|
||||||
lock (StateLock)
|
lock (StateLock)
|
||||||
{
|
{
|
||||||
resources.Remove(resourceReference);
|
resourceHandles.Remove(resourceReference);
|
||||||
|
|
||||||
|
if (resourceReference.Target is UpdatingSourceVoice updatableVoice)
|
||||||
|
{
|
||||||
|
updatingSourceVoices.Remove(updatableVoice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,18 +298,18 @@ namespace MoonWorks.Audio
|
||||||
Thread.Join();
|
Thread.Join();
|
||||||
|
|
||||||
// dispose all source voices first
|
// dispose all source voices first
|
||||||
foreach (var resource in resources)
|
foreach (var handle in resourceHandles)
|
||||||
{
|
{
|
||||||
if (resource.Target is SourceVoice voice)
|
if (handle.Target is SourceVoice voice)
|
||||||
{
|
{
|
||||||
voice.Dispose();
|
voice.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dispose all submix voices except the faux mastering voice
|
// dispose all submix voices except the faux mastering voice
|
||||||
foreach (var resource in resources)
|
foreach (var handle in resourceHandles)
|
||||||
{
|
{
|
||||||
if (resource.Target is SubmixVoice voice && voice != fauxMasteringVoice)
|
if (handle.Target is SubmixVoice voice && voice != fauxMasteringVoice)
|
||||||
{
|
{
|
||||||
voice.Dispose();
|
voice.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -317,15 +322,15 @@ namespace MoonWorks.Audio
|
||||||
FAudio.FAudioVoice_DestroyVoice(trueMasteringVoice);
|
FAudio.FAudioVoice_DestroyVoice(trueMasteringVoice);
|
||||||
|
|
||||||
// destroy all other audio resources
|
// destroy all other audio resources
|
||||||
foreach (var resource in resources)
|
foreach (var handle in resourceHandles)
|
||||||
{
|
{
|
||||||
if (resource.Target is IDisposable disposable)
|
if (handle.Target is AudioResource resource)
|
||||||
{
|
{
|
||||||
disposable.Dispose();
|
resource.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resources.Clear();
|
resourceHandles.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
FAudio.FAudio_Release(Handle);
|
FAudio.FAudio_Release(Handle);
|
||||||
|
|
Loading…
Reference in New Issue