From d72412d24d6b68c137cdd247f553e07ae3eab4cd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 7 Jan 2019 19:28:46 +0900 Subject: [PATCH 1/2] Fix leaderboard not correctly handling cancellation --- osu.Game/Online/Leaderboards/Leaderboard.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/Leaderboards/Leaderboard.cs b/osu.Game/Online/Leaderboards/Leaderboard.cs index f3bf16a05f..2aeb503224 100644 --- a/osu.Game/Online/Leaderboards/Leaderboard.cs +++ b/osu.Game/Online/Leaderboards/Leaderboard.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -30,6 +31,7 @@ namespace osu.Game.Online.Leaderboards private readonly LoadingAnimation loading; private ScheduledDelegate showScoresDelegate; + private CancellationTokenSource showScoresCancellationSource; private bool scoresLoadedOnce; @@ -60,6 +62,8 @@ namespace osu.Game.Online.Leaderboards // schedule because we may not be loaded yet (LoadComponentAsync complains). showScoresDelegate?.Cancel(); + showScoresCancellationSource?.Cancel(); + if (!IsLoaded) showScoresDelegate = Schedule(showScores); else @@ -77,7 +81,7 @@ namespace osu.Game.Online.Leaderboards } scrollContainer.ScrollTo(0f, false); - }); + }, (showScoresCancellationSource = new CancellationTokenSource()).Token); } } From 8eedef3e8638fa9a4134c5a423f5e6025773ed22 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 7 Jan 2019 19:31:05 +0900 Subject: [PATCH 2/2] Move cancellation to safer place --- osu.Game/Online/Leaderboards/Leaderboard.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/Leaderboards/Leaderboard.cs b/osu.Game/Online/Leaderboards/Leaderboard.cs index 2aeb503224..a6748fa983 100644 --- a/osu.Game/Online/Leaderboards/Leaderboard.cs +++ b/osu.Game/Online/Leaderboards/Leaderboard.cs @@ -51,6 +51,10 @@ namespace osu.Game.Online.Leaderboards loading.Hide(); + // schedule because we may not be loaded yet (LoadComponentAsync complains). + showScoresDelegate?.Cancel(); + showScoresCancellationSource?.Cancel(); + if (scores == null || !scores.Any()) return; @@ -60,10 +64,6 @@ namespace osu.Game.Online.Leaderboards scrollFlow = CreateScoreFlow(); scrollFlow.ChildrenEnumerable = scores.Select((s, index) => CreateDrawableScore(s, index + 1)); - // schedule because we may not be loaded yet (LoadComponentAsync complains). - showScoresDelegate?.Cancel(); - showScoresCancellationSource?.Cancel(); - if (!IsLoaded) showScoresDelegate = Schedule(showScores); else