mirror of
https://github.com/ppy/osu
synced 2025-03-21 18:38:25 +00:00
Merge pull request #2292 from peppy/fix-player-disposal
Fix player not getting disposed in some scenarios
This commit is contained in:
commit
15b33af6c8
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -27,6 +28,8 @@ namespace osu.Game.Screens.Play
|
|||||||
private bool showOverlays = true;
|
private bool showOverlays = true;
|
||||||
public override bool ShowOverlaysOnEnter => showOverlays;
|
public override bool ShowOverlaysOnEnter => showOverlays;
|
||||||
|
|
||||||
|
private Task loadTask;
|
||||||
|
|
||||||
public PlayerLoader(Player player)
|
public PlayerLoader(Player player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -55,7 +58,7 @@ namespace osu.Game.Screens.Play
|
|||||||
Margin = new MarginPadding(25)
|
Margin = new MarginPadding(25)
|
||||||
});
|
});
|
||||||
|
|
||||||
LoadComponentAsync(player);
|
loadTask = LoadComponentAsync(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnResuming(Screen last)
|
protected override void OnResuming(Screen last)
|
||||||
@ -65,7 +68,7 @@ namespace osu.Game.Screens.Play
|
|||||||
contentIn();
|
contentIn();
|
||||||
|
|
||||||
//we will only be resumed if the player has requested a re-run (see ValidForResume setting above)
|
//we will only be resumed if the player has requested a re-run (see ValidForResume setting above)
|
||||||
LoadComponentAsync(player = new Player
|
loadTask = LoadComponentAsync(player = new Player
|
||||||
{
|
{
|
||||||
RestartCount = player.RestartCount + 1,
|
RestartCount = player.RestartCount + 1,
|
||||||
RestartRequested = player.RestartRequested,
|
RestartRequested = player.RestartRequested,
|
||||||
@ -154,6 +157,8 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
if (!IsCurrentScreen) return;
|
if (!IsCurrentScreen) return;
|
||||||
|
|
||||||
|
loadTask = null;
|
||||||
|
|
||||||
if (!Push(player))
|
if (!Push(player))
|
||||||
Exit();
|
Exit();
|
||||||
else
|
else
|
||||||
@ -192,6 +197,14 @@ namespace osu.Game.Screens.Play
|
|||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
// if the player never got pushed, we should explicitly dispose it.
|
||||||
|
loadTask?.ContinueWith(_ => player.Dispose());
|
||||||
|
}
|
||||||
|
|
||||||
private class BeatmapMetadataDisplay : Container
|
private class BeatmapMetadataDisplay : Container
|
||||||
{
|
{
|
||||||
private class MetadataLine : Container
|
private class MetadataLine : Container
|
||||||
|
@ -48,13 +48,15 @@ namespace osu.Game.Skinning
|
|||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onSourceChanged() => SourceChanged?.Invoke();
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
||||||
{
|
{
|
||||||
var dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
var dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
||||||
|
|
||||||
fallbackSource = dependencies.Get<ISkinSource>();
|
fallbackSource = dependencies.Get<ISkinSource>();
|
||||||
if (fallbackSource != null)
|
if (fallbackSource != null)
|
||||||
fallbackSource.SourceChanged += () => SourceChanged?.Invoke();
|
fallbackSource.SourceChanged += onSourceChanged;
|
||||||
|
|
||||||
dependencies.CacheAs<ISkinSource>(this);
|
dependencies.CacheAs<ISkinSource>(this);
|
||||||
|
|
||||||
@ -66,7 +68,7 @@ namespace osu.Game.Skinning
|
|||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (fallbackSource != null)
|
if (fallbackSource != null)
|
||||||
fallbackSource.SourceChanged -= SourceChanged;
|
fallbackSource.SourceChanged -= onSourceChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user