mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:03:22 +08: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>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -27,6 +28,8 @@ namespace osu.Game.Screens.Play
|
||||
private bool showOverlays = true;
|
||||
public override bool ShowOverlaysOnEnter => showOverlays;
|
||||
|
||||
private Task loadTask;
|
||||
|
||||
public PlayerLoader(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
@ -55,7 +58,7 @@ namespace osu.Game.Screens.Play
|
||||
Margin = new MarginPadding(25)
|
||||
});
|
||||
|
||||
LoadComponentAsync(player);
|
||||
loadTask = LoadComponentAsync(player);
|
||||
}
|
||||
|
||||
protected override void OnResuming(Screen last)
|
||||
@ -65,7 +68,7 @@ namespace osu.Game.Screens.Play
|
||||
contentIn();
|
||||
|
||||
//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,
|
||||
RestartRequested = player.RestartRequested,
|
||||
@ -154,6 +157,8 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
if (!IsCurrentScreen) return;
|
||||
|
||||
loadTask = null;
|
||||
|
||||
if (!Push(player))
|
||||
Exit();
|
||||
else
|
||||
@ -192,6 +197,14 @@ namespace osu.Game.Screens.Play
|
||||
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 MetadataLine : Container
|
||||
|
@ -48,13 +48,15 @@ namespace osu.Game.Skinning
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
private void onSourceChanged() => SourceChanged?.Invoke();
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
||||
|
||||
fallbackSource = dependencies.Get<ISkinSource>();
|
||||
if (fallbackSource != null)
|
||||
fallbackSource.SourceChanged += () => SourceChanged?.Invoke();
|
||||
fallbackSource.SourceChanged += onSourceChanged;
|
||||
|
||||
dependencies.CacheAs<ISkinSource>(this);
|
||||
|
||||
@ -66,7 +68,7 @@ namespace osu.Game.Skinning
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (fallbackSource != null)
|
||||
fallbackSource.SourceChanged -= SourceChanged;
|
||||
fallbackSource.SourceChanged -= onSourceChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user