1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 05:22:54 +08:00

Fix incorrect cancellation / disposal handling of DetachedBeatmapStore

This commit is contained in:
Dean Herbert 2024-08-28 16:17:03 +09:00
parent 4d42274771
commit 081c9eb21b
No known key found for this signature in database
2 changed files with 6 additions and 7 deletions

View File

@ -7,7 +7,6 @@ using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using Realms;
@ -24,11 +23,9 @@ namespace osu.Game.Database
[Resolved]
private RealmAccess realm { get; set; } = null!;
public IBindableList<BeatmapSetInfo> GetDetachedBeatmaps()
public IBindableList<BeatmapSetInfo> GetDetachedBeatmaps(CancellationToken cancellationToken)
{
if (!loaded.Wait(60000))
Logger.Error(new TimeoutException("Beatmaps did not load in an acceptable time"), $"{nameof(DetachedBeatmapStore)} fell over");
loaded.Wait(cancellationToken);
return detachedBeatmapSets.GetBoundCopy();
}
@ -75,6 +72,7 @@ namespace osu.Game.Database
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
loaded.Set();
realmSubscription?.Dispose();
}

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
@ -235,7 +236,7 @@ namespace osu.Game.Screens.Select
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, AudioManager audio, DetachedBeatmapStore beatmapStore)
private void load(OsuConfigManager config, AudioManager audio, CancellationToken cancellationToken)
{
spinSample = audio.Samples.Get("SongSelect/random-spin");
randomSelectSample = audio.Samples.Get(@"SongSelect/select-random");
@ -251,7 +252,7 @@ namespace osu.Game.Screens.Select
// This is performing an unnecessary second lookup on realm (in addition to the subscription), but for performance reasons
// we require it to be separate: the subscription's initial callback (with `ChangeSet` of `null`) will run on the update
// thread. If we attempt to detach beatmaps in this callback the game will fall over (it takes time).
detachedBeatmapSets = detachedBeatmapStore!.GetDetachedBeatmaps();
detachedBeatmapSets = detachedBeatmapStore!.GetDetachedBeatmaps(cancellationToken);
detachedBeatmapSets.BindCollectionChanged(beatmapSetsChanged);
loadBeatmapSets(detachedBeatmapSets);
}