From 998d8206668ba1733d7f7d6ff1afacde219f8a3a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Feb 2024 00:21:54 +0800 Subject: [PATCH] Ensure audio filters can't be attached before load (or post-disposal) Will probably fix https://github.com/ppy/osu/issues/27225? --- osu.Game/Audio/Effects/AudioFilter.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/osu.Game/Audio/Effects/AudioFilter.cs b/osu.Game/Audio/Effects/AudioFilter.cs index 682ca4ca7be0..c8673372d7f7 100644 --- a/osu.Game/Audio/Effects/AudioFilter.cs +++ b/osu.Game/Audio/Effects/AudioFilter.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using ManagedBass.Fx; using osu.Framework.Audio.Mixing; +using osu.Framework.Caching; using osu.Framework.Graphics; namespace osu.Game.Audio.Effects @@ -22,6 +23,8 @@ public partial class AudioFilter : Component, ITransformableFilter private bool isAttached; + private readonly Cached filterApplication = new Cached(); + private int cutoff; /// @@ -36,7 +39,7 @@ public int Cutoff return; cutoff = value; - updateFilter(cutoff); + filterApplication.Invalidate(); } } @@ -61,6 +64,17 @@ public AudioFilter(AudioMixer mixer, BQFType type = BQFType.LowPass) Cutoff = getInitialCutoff(type); } + protected override void Update() + { + base.Update(); + + if (!filterApplication.IsValid) + { + updateFilter(cutoff); + filterApplication.Validate(); + } + } + private int getInitialCutoff(BQFType type) { switch (type)