From f16ef1ee69fafc74caeb3c3a0964fca3fe58fbfd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 26 Nov 2021 22:34:05 +0900 Subject: [PATCH] Reapply schedule workaround for `PreviewTrack` --- .../Drawables/Cards/Buttons/PlayButton.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs b/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs index 4574d37da0..f7bab26666 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs @@ -97,6 +97,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons if (previewTrack == null) { toggleLoading(true); + LoadComponentAsync(previewTrack = previewTrackManager.Get(beatmapSetInfo), onPreviewLoaded); } else @@ -112,18 +113,23 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons private void onPreviewLoaded(PreviewTrack loadedPreview) { - // another async load might have completed before this one. - // if so, do not make any changes. - if (loadedPreview != previewTrack) - return; + // Make sure that we schedule to after the next audio frame to fix crashes in single-threaded execution. + // See: https://github.com/ppy/osu-framework/issues/4692 + Schedule(() => + { + // another async load might have completed before this one. + // if so, do not make any changes. + if (loadedPreview != previewTrack) + return; - AddInternal(loadedPreview); - toggleLoading(false); + AddInternal(loadedPreview); + toggleLoading(false); - loadedPreview.Stopped += () => Schedule(() => Playing.Value = false); + loadedPreview.Stopped += () => Schedule(() => Playing.Value = false); - if (Playing.Value) - tryStartPreview(); + if (Playing.Value) + tryStartPreview(); + }); } private void tryStartPreview()