diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackgroundWithStoryboard.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackgroundWithStoryboard.cs index 1e702967b6..2bde71a6a1 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackgroundWithStoryboard.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackgroundWithStoryboard.cs @@ -71,7 +71,7 @@ namespace osu.Game.Graphics.Backgrounds }, (loadCancellationSource = new CancellationTokenSource()).Token); } - public void UnloadStoryboard(Action scheduleStoryboardRemoval) + public void UnloadStoryboard() { if (drawableStoryboard == null) return; @@ -79,15 +79,12 @@ namespace osu.Game.Graphics.Backgrounds loadCancellationSource.AsNonNull().Cancel(); loadCancellationSource = null; - DrawableStoryboard s = drawableStoryboard; - - scheduleStoryboardRemoval(() => - { - s.RemoveAndDisposeImmediately(); - Sprite.Alpha = 1f; - }); + // clear is intentionally used here for the storyboard to be disposed asynchronously. + storyboardContainer.Clear(); drawableStoryboard = null; + + Sprite.Alpha = 1f; } protected override void LoadComplete() diff --git a/osu.Game/Screens/BackgroundScreenStack.cs b/osu.Game/Screens/BackgroundScreenStack.cs index 9af6601aa4..2c7b219791 100644 --- a/osu.Game/Screens/BackgroundScreenStack.cs +++ b/osu.Game/Screens/BackgroundScreenStack.cs @@ -35,6 +35,6 @@ namespace osu.Game.Screens return true; } - internal void ScheduleToTransitionEnd(Action action) => Scheduler.AddDelayed(action, BackgroundScreen.TRANSITION_LENGTH); + internal ScheduledDelegate ScheduleUntilTransitionEnd(Action action) => Scheduler.AddDelayed(action, BackgroundScreen.TRANSITION_LENGTH); } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 07b1cc6df4..4583b3e4d6 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -73,13 +73,15 @@ namespace osu.Game.Screens.Backgrounds void next() => Next(); } + private ScheduledDelegate storyboardUnloadDelegate; + public override void OnSuspending(ScreenTransitionEvent e) { var backgroundScreenStack = Parent as BackgroundScreenStack; Debug.Assert(backgroundScreenStack != null); if (background is BeatmapBackgroundWithStoryboard storyboardBackground) - storyboardBackground.UnloadStoryboard(backgroundScreenStack.ScheduleToTransitionEnd); + storyboardUnloadDelegate = backgroundScreenStack.ScheduleUntilTransitionEnd(storyboardBackground.UnloadStoryboard); base.OnSuspending(e); } @@ -87,7 +89,14 @@ namespace osu.Game.Screens.Backgrounds public override void OnResuming(ScreenTransitionEvent e) { if (background is BeatmapBackgroundWithStoryboard storyboardBackground) - storyboardBackground.LoadStoryboard(); + { + if (storyboardUnloadDelegate?.Completed == false) + storyboardUnloadDelegate.Cancel(); + else + storyboardBackground.LoadStoryboard(); + + storyboardUnloadDelegate = null; + } base.OnResuming(e); }