diff --git a/osu.Game/Screens/BackgroundScreenStack.cs b/osu.Game/Screens/BackgroundScreenStack.cs
index 294f23d2ac..9f562a618e 100644
--- a/osu.Game/Screens/BackgroundScreenStack.cs
+++ b/osu.Game/Screens/BackgroundScreenStack.cs
@@ -17,15 +17,21 @@ namespace osu.Game.Screens
Origin = Anchor.Centre;
}
- public void Push(BackgroundScreen screen)
+ ///
+ /// Attempt to push a new background screen to this stack.
+ ///
+ /// The screen to attempt to push.
+ /// Whether the push succeeded. For example, if the existing screen was already of the correct type this will return false.
+ public bool Push(BackgroundScreen screen)
{
if (screen == null)
- return;
+ return false;
if (EqualityComparer.Default.Equals((BackgroundScreen)CurrentScreen, screen))
- return;
+ return false;
base.Push(screen);
+ return true;
}
}
}
diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs
index e3fe14a585..9aec2a5c19 100644
--- a/osu.Game/Screens/OsuScreen.cs
+++ b/osu.Game/Screens/OsuScreen.cs
@@ -186,17 +186,14 @@ namespace osu.Game.Screens
{
applyArrivingDefaults(false);
- backgroundStack?.Push(ownedBackground = CreateBackground());
-
- background = backgroundStack?.CurrentScreen as BackgroundScreen;
-
- if (background != ownedBackground)
+ if (backgroundStack?.Push(ownedBackground = CreateBackground()) != true)
{
- // background may have not been replaced, at which point we don't want to track the background lifetime.
+ // If the constructed instance was not actually pushed to the background stack, we don't want to track it unnecessarily.
ownedBackground?.Dispose();
ownedBackground = null;
}
+ background = backgroundStack?.CurrentScreen as BackgroundScreen;
base.OnEntering(last);
}