Merge pull request #15821 from peppy/reapply-preview-track-workaround

Fix potential crashes when playing preview tracks in single thread mode
This commit is contained in:
Dan Balasescu 2021-11-27 00:24:36 +09:00 committed by GitHub
commit ed5f7039d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,6 +97,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
if (previewTrack == null) if (previewTrack == null)
{ {
toggleLoading(true); toggleLoading(true);
LoadComponentAsync(previewTrack = previewTrackManager.Get(beatmapSetInfo), onPreviewLoaded); LoadComponentAsync(previewTrack = previewTrackManager.Get(beatmapSetInfo), onPreviewLoaded);
} }
else else
@ -112,18 +113,23 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
private void onPreviewLoaded(PreviewTrack loadedPreview) private void onPreviewLoaded(PreviewTrack loadedPreview)
{ {
// another async load might have completed before this one. // Make sure that we schedule to after the next audio frame to fix crashes in single-threaded execution.
// if so, do not make any changes. // See: https://github.com/ppy/osu-framework/issues/4692
if (loadedPreview != previewTrack) Schedule(() =>
return; {
// another async load might have completed before this one.
// if so, do not make any changes.
if (loadedPreview != previewTrack)
return;
AddInternal(loadedPreview); AddInternal(loadedPreview);
toggleLoading(false); toggleLoading(false);
loadedPreview.Stopped += () => Schedule(() => Playing.Value = false); loadedPreview.Stopped += () => Schedule(() => Playing.Value = false);
if (Playing.Value) if (Playing.Value)
tryStartPreview(); tryStartPreview();
});
} }
private void tryStartPreview() private void tryStartPreview()