Ensure global beatmap/ruleset are always mutated from the update thread

This came up while testing the new realm thread, where `MusicController`
would fall over when `OsuTestScene` changes the global beatmap from an
async load thread (causing a cross-thread realm access).

We don't want to have to schedule every usage of these bindables, so
this seems like a good constraint to put in place.
This commit is contained in:
Dean Herbert 2022-01-18 12:20:52 +09:00
parent e9c96908d5
commit b9ec860cf2
1 changed files with 10 additions and 0 deletions

View File

@ -327,6 +327,7 @@ List<ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
dependencies.CacheAs(MusicController);
Ruleset.BindValueChanged(onRulesetChanged);
Beatmap.BindValueChanged(onBeatmapChanged);
}
protected virtual void InitialiseFonts()
@ -448,8 +449,17 @@ public void Migrate(string path)
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage);
private void onBeatmapChanged(ValueChangedEvent<WorkingBeatmap> valueChangedEvent)
{
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException("Global beatmap bindable must be changed from update thread.");
}
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r)
{
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException("Global ruleset bindable must be changed from update thread.");
if (r.NewValue?.Available != true)
{
// reject the change if the ruleset is not available.