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

Merge pull request #18833 from peppy/beatmap-manager-misc

Ensure `WorkingBeatmap` is always using a detached instance
This commit is contained in:
Bartłomiej Dach 2022-06-24 13:06:09 +02:00 committed by GitHub
commit a329b346a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -418,22 +418,24 @@ namespace osu.Game.Beatmaps
#region Implementation of IWorkingBeatmapCache
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? importedBeatmap)
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? beatmapInfo)
{
// Detached sets don't come with files.
// If we seem to be missing files, now is a good time to re-fetch.
if (importedBeatmap?.BeatmapSet?.Files.Count == 0)
if (beatmapInfo?.IsManaged == true || beatmapInfo?.BeatmapSet?.Files.Count == 0)
{
Realm.Run(r =>
{
var refetch = r.Find<BeatmapInfo>(importedBeatmap.ID)?.Detach();
var refetch = r.Find<BeatmapInfo>(beatmapInfo.ID)?.Detach();
if (refetch != null)
importedBeatmap = refetch;
beatmapInfo = refetch;
});
}
return workingBeatmapCache.GetWorkingBeatmap(importedBeatmap);
Debug.Assert(beatmapInfo?.IsManaged != true);
return workingBeatmapCache.GetWorkingBeatmap(beatmapInfo);
}
void IWorkingBeatmapCache.Invalidate(BeatmapSetInfo beatmapSetInfo) => workingBeatmapCache.Invalidate(beatmapSetInfo);