From c037b4cb69a5a0053e5bb661796ba3d09509ff9b Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 11 May 2023 18:59:26 -0700 Subject: [PATCH] fix StaticSoundInstance race condition and state --- lib/FAudio | 2 +- src/Audio/StaticSound.cs | 3 ++- src/Audio/StaticSoundInstance.cs | 16 +++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/FAudio b/lib/FAudio index 63071f2c..590cc353 160000 --- a/lib/FAudio +++ b/lib/FAudio @@ -1 +1 @@ -Subproject commit 63071f2c309f6fc2193de1c6b85da0e31df80040 +Subproject commit 590cc3537f64d3b118f0001a2f2c111fcbd2b23f diff --git a/src/Audio/StaticSound.cs b/src/Audio/StaticSound.cs index 74a82d80..d3ecd252 100644 --- a/src/Audio/StaticSound.cs +++ b/src/Audio/StaticSound.cs @@ -274,10 +274,11 @@ namespace MoonWorks.Audio { if (AvailableInstances.Count == 0) { - AvailableInstances.Push(new StaticSoundInstance(Device, this, autoFree)); + AvailableInstances.Push(new StaticSoundInstance(Device, this)); } var instance = AvailableInstances.Pop(); + instance.AutoFree = autoFree; UsedInstances.Add(instance); return instance; } diff --git a/src/Audio/StaticSoundInstance.cs b/src/Audio/StaticSoundInstance.cs index d958606c..79fc27b5 100644 --- a/src/Audio/StaticSoundInstance.cs +++ b/src/Audio/StaticSoundInstance.cs @@ -32,21 +32,14 @@ namespace MoonWorks.Audio } } - public bool AutoFree { get; } + public bool AutoFree { get; internal set; } internal StaticSoundInstance( AudioDevice device, - StaticSound parent, - bool autoFree + StaticSound parent ) : base(device, parent.FormatTag, parent.BitsPerSample, parent.BlockAlign, parent.Channels, parent.SamplesPerSecond) { Parent = parent; - AutoFree = autoFree; - - if (AutoFree) - { - device.AddAutoFreeStaticSoundInstance(this); - } } public override void Play() @@ -87,6 +80,11 @@ namespace MoonWorks.Audio FAudio.FAudioSourceVoice_Start(Voice, 0, operationSet); State = SoundState.Playing; + + if (AutoFree) + { + Device.AddAutoFreeStaticSoundInstance(this); + } } public override void Pause()