Ensure spectator player is unsubscribed to prevent leak

This commit is contained in:
Bartłomiej Dach 2020-11-01 16:03:28 +01:00
parent 23d9fa4dfa
commit 716458344f

View File

@ -26,12 +26,6 @@ namespace osu.Game.Screens.Play
spectatorStreaming.OnUserBeganPlaying += userBeganPlaying;
}
private void userBeganPlaying(int userId, SpectatorState state)
{
if (userId == Score.ScoreInfo.UserID)
Schedule(this.Exit);
}
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
{
// if we already have frames, start gameplay at the point in time they exist, should they be too far into the beatmap.
@ -42,5 +36,25 @@ namespace osu.Game.Screens.Play
return new GameplayClockContainer(beatmap, firstFrameTime.Value, true);
}
public override bool OnExiting(IScreen next)
{
spectatorStreaming.OnUserBeganPlaying -= userBeganPlaying;
return base.OnExiting(next);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (spectatorStreaming != null)
spectatorStreaming.OnUserBeganPlaying -= userBeganPlaying;
}
private void userBeganPlaying(int userId, SpectatorState state)
{
if (userId == Score.ScoreInfo.UserID)
Schedule(this.Exit);
}
}
}