From d788931661e6110393f011ca3512582ab168c46c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 3 Nov 2020 19:53:35 +0900 Subject: [PATCH] Fix LoadComponentAsync calls potentially occuring after beatmap wedge disposal As seen in https://ci.appveyor.com/project/peppy/osu/builds/36109658/tests. Also adds cancellation logic for good measure. --- osu.Game/Screens/Select/BeatmapInfoWedge.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index bdfcc2fd96..ad3bce8968 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using JetBrains.Annotations; using osuTK; using osuTK.Graphics; @@ -85,6 +86,8 @@ namespace osu.Game.Screens.Select private WorkingBeatmap beatmap; + private CancellationTokenSource cancellationSource; + public WorkingBeatmap Beatmap { get => beatmap; @@ -93,10 +96,12 @@ namespace osu.Game.Screens.Select if (beatmap == value) return; beatmap = value; + cancellationSource?.Cancel(); + cancellationSource = new CancellationTokenSource(); beatmapDifficulty?.UnbindAll(); - beatmapDifficulty = difficultyManager.GetBindableDifficulty(beatmap.BeatmapInfo); - beatmapDifficulty.BindValueChanged(_ => updateDisplay()); + beatmapDifficulty = difficultyManager.GetBindableDifficulty(beatmap.BeatmapInfo, cancellationSource.Token); + beatmapDifficulty.BindValueChanged(_ => Schedule(updateDisplay)); updateDisplay(); } @@ -137,6 +142,12 @@ namespace osu.Game.Screens.Select }); } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + cancellationSource?.Cancel(); + } + public class BufferedWedgeInfo : BufferedContainer { public OsuSpriteText VersionLabel { get; private set; }