From b705313d3f3bcd950bbb6076de995c91c82cbd18 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 28 Jan 2026 23:09:08 +0900 Subject: [PATCH] Fix `BeatmapDifficultyCache`'s bindable tracking not correctly updating `BeatmapInfo` metadata on invalidation --- osu.Game/Beatmaps/BeatmapDifficultyCache.cs | 25 ++++++++++++++++++--- osu.Game/Beatmaps/BeatmapUpdater.cs | 6 ++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapDifficultyCache.cs b/osu.Game/Beatmaps/BeatmapDifficultyCache.cs index 2183cf00df..291239e350 100644 --- a/osu.Game/Beatmaps/BeatmapDifficultyCache.cs +++ b/osu.Game/Beatmaps/BeatmapDifficultyCache.cs @@ -95,9 +95,28 @@ namespace osu.Game.Beatmaps }, true); } - public void Invalidate(IBeatmapInfo beatmap) + /// + /// Notify this cache that a beatmap has been invalidated/updated. + /// + /// The old beatmap model. + /// The updated beatmap model. + public void Invalidate(IBeatmapInfo oldBeatmap, IBeatmapInfo newBeatmap) { - base.Invalidate(lookup => lookup.BeatmapInfo.Equals(beatmap)); + base.Invalidate(lookup => lookup.BeatmapInfo.Equals(oldBeatmap)); + + lock (bindableUpdateLock) + { + bool trackedBindablesRefreshRequired = false; + + foreach (var bsd in trackedBindables.Where(bsd => bsd.BeatmapInfo.Equals(oldBeatmap))) + { + bsd.BeatmapInfo = newBeatmap; + trackedBindablesRefreshRequired = true; + } + + if (trackedBindablesRefreshRequired) + Scheduler.AddOnce(updateTrackedBindables); + } } /// @@ -358,7 +377,7 @@ namespace osu.Game.Beatmaps private class BindableStarDifficulty : Bindable { - public readonly IBeatmapInfo BeatmapInfo; + public IBeatmapInfo BeatmapInfo; public readonly CancellationToken CancellationToken; public BindableStarDifficulty(IBeatmapInfo beatmapInfo, CancellationToken cancellationToken) diff --git a/osu.Game/Beatmaps/BeatmapUpdater.cs b/osu.Game/Beatmaps/BeatmapUpdater.cs index ff23bf1242..72c69393df 100644 --- a/osu.Game/Beatmaps/BeatmapUpdater.cs +++ b/osu.Game/Beatmaps/BeatmapUpdater.cs @@ -52,11 +52,11 @@ namespace osu.Game.Beatmaps foreach (BeatmapInfo beatmap in beatmapSet.Beatmaps) { - difficultyCache.Invalidate(beatmap); - var working = workingBeatmapCache.GetWorkingBeatmap(beatmap); - var ruleset = working.BeatmapInfo.Ruleset.CreateInstance(); + difficultyCache.Invalidate(beatmap, working.BeatmapInfo); + + var ruleset = working.BeatmapInfo.Ruleset.CreateInstance(); var calculator = ruleset.CreateDifficultyCalculator(working); beatmap.StarRating = calculator.Calculate().StarRating;