mirror of https://github.com/ppy/osu
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:
parent
e9c96908d5
commit
b9ec860cf2
|
@ -327,6 +327,7 @@ List<ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
|
||||||
dependencies.CacheAs(MusicController);
|
dependencies.CacheAs(MusicController);
|
||||||
|
|
||||||
Ruleset.BindValueChanged(onRulesetChanged);
|
Ruleset.BindValueChanged(onRulesetChanged);
|
||||||
|
Beatmap.BindValueChanged(onBeatmapChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void InitialiseFonts()
|
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);
|
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)
|
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)
|
if (r.NewValue?.Available != true)
|
||||||
{
|
{
|
||||||
// reject the change if the ruleset is not available.
|
// reject the change if the ruleset is not available.
|
||||||
|
|
Loading…
Reference in New Issue