Ensure OsuScreen level leases are taken out synchronously

This commit is contained in:
Dean Herbert
2020-01-31 19:10:44 +09:00
parent d5b9df049b
commit 19f516e710
11 changed files with 79 additions and 36 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Internal;
using osu.Framework.Allocation;
@ -95,15 +96,30 @@ namespace osu.Game.Screens
public Bindable<IReadOnlyList<Mod>> Mods { get; private set; }
private OsuScreenDependencies screenDependencies;
internal void CreateLeasedDependencies(IReadOnlyDependencyContainer dependencies) => createDependencies(dependencies);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, parent);
if (screenDependencies == null)
{
if (DisallowExternalBeatmapRulesetChanges)
throw new InvalidOperationException($"Screens that specify {nameof(DisallowExternalBeatmapRulesetChanges)} must be pushed immediately.");
createDependencies(parent);
}
return base.CreateChildDependencies(screenDependencies);
}
private void createDependencies(IReadOnlyDependencyContainer dependencies)
{
screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, dependencies);
Beatmap = screenDependencies.Beatmap;
Ruleset = screenDependencies.Ruleset;
Mods = screenDependencies.Mods;
return base.CreateChildDependencies(screenDependencies);
}
protected BackgroundScreen Background => backgroundStack?.CurrentScreen as BackgroundScreen;