1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

Merge pull request #18964 from peppy/fix-beatmap-leaderboard-null

Fix potential crash in `BeatmapLeaderboard` during rapid refresh operations
This commit is contained in:
Dan Balasescu 2022-07-01 17:01:57 +09:00 committed by GitHub
commit ee963f8aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -111,7 +112,7 @@ namespace osu.Game.Screens.Select.Leaderboards
if (Scope == BeatmapLeaderboardScope.Local) if (Scope == BeatmapLeaderboardScope.Local)
{ {
subscribeToLocalScores(cancellationToken); subscribeToLocalScores(fetchBeatmapInfo, cancellationToken);
return null; return null;
} }
@ -174,14 +175,13 @@ namespace osu.Game.Screens.Select.Leaderboards
Action = () => ScoreSelected?.Invoke(model) Action = () => ScoreSelected?.Invoke(model)
}; };
private void subscribeToLocalScores(CancellationToken cancellationToken) private void subscribeToLocalScores(BeatmapInfo beatmapInfo, CancellationToken cancellationToken)
{ {
Debug.Assert(beatmapInfo != null);
scoreSubscription?.Dispose(); scoreSubscription?.Dispose();
scoreSubscription = null; scoreSubscription = null;
if (beatmapInfo == null)
return;
scoreSubscription = realm.RegisterForNotifications(r => scoreSubscription = realm.RegisterForNotifications(r =>
r.All<ScoreInfo>().Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $0" r.All<ScoreInfo>().Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $0"
+ $" AND {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $1" + $" AND {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $1"