1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 10:53:22 +08:00

Merge pull request #10678 from peppy/fix-load-async-after-disposal-beatmap-wedge

Fix LoadComponentAsync calls potentially occuring after beatmap wedge disposal
This commit is contained in:
Dan Balasescu 2020-11-04 13:10:41 +09:00 committed by GitHub
commit 9b2f396006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,9 +96,11 @@ namespace osu.Game.Screens.Select
if (beatmap == value) return;
beatmap = value;
cancellationSource?.Cancel();
cancellationSource = new CancellationTokenSource();
beatmapDifficulty?.UnbindAll();
beatmapDifficulty = difficultyManager.GetBindableDifficulty(beatmap.BeatmapInfo);
beatmapDifficulty = difficultyManager.GetBindableDifficulty(beatmap.BeatmapInfo, cancellationSource.Token);
beatmapDifficulty.BindValueChanged(_ => updateDisplay());
updateDisplay();
@ -108,33 +113,44 @@ namespace osu.Game.Screens.Select
private void updateDisplay()
{
void removeOldInfo()
{
State.Value = beatmap == null ? Visibility.Hidden : Visibility.Visible;
Scheduler.AddOnce(perform);
Info?.FadeOut(250);
Info?.Expire();
Info = null;
void perform()
{
void removeOldInfo()
{
State.Value = beatmap == null ? Visibility.Hidden : Visibility.Visible;
Info?.FadeOut(250);
Info?.Expire();
Info = null;
}
if (beatmap == null)
{
removeOldInfo();
return;
}
LoadComponentAsync(loadingInfo = new BufferedWedgeInfo(beatmap, ruleset.Value, beatmapDifficulty.Value)
{
Shear = -Shear,
Depth = Info?.Depth + 1 ?? 0
}, loaded =>
{
// ensure we are the most recent loaded wedge.
if (loaded != loadingInfo) return;
removeOldInfo();
Add(Info = loaded);
});
}
}
if (beatmap == null)
{
removeOldInfo();
return;
}
LoadComponentAsync(loadingInfo = new BufferedWedgeInfo(beatmap, ruleset.Value, beatmapDifficulty.Value)
{
Shear = -Shear,
Depth = Info?.Depth + 1 ?? 0
}, loaded =>
{
// ensure we are the most recent loaded wedge.
if (loaded != loadingInfo) return;
removeOldInfo();
Add(Info = loaded);
});
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
cancellationSource?.Cancel();
}
public class BufferedWedgeInfo : BufferedContainer