1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 13:22:55 +08:00

Merge pull request #1162 from peppy/nullref-fix

Fix a nullref when reaching the results screen with no user provided
This commit is contained in:
Dan Balasescu 2017-08-22 18:56:06 +09:00 committed by GitHub
commit ad16f41e26

View File

@ -23,6 +23,7 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -50,6 +51,8 @@ namespace osu.Game.Screens.Play
private RulesetInfo ruleset; private RulesetInfo ruleset;
private APIAccess api;
private ScoreProcessor scoreProcessor; private ScoreProcessor scoreProcessor;
protected RulesetContainer RulesetContainer; protected RulesetContainer RulesetContainer;
@ -68,10 +71,13 @@ namespace osu.Game.Screens.Play
private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true; private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true;
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config, OsuGame osu) private void load(AudioManager audio, OsuConfigManager config, APIAccess api)
{ {
this.api = api;
dimLevel = config.GetBindable<double>(OsuSetting.DimLevel); dimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel); mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
sampleRestart = audio.Sample.Get(@"Gameplay/restart"); sampleRestart = audio.Sample.Get(@"Gameplay/restart");
@ -86,7 +92,7 @@ namespace osu.Game.Screens.Play
if (beatmap == null) if (beatmap == null)
throw new InvalidOperationException("Beatmap was not loaded"); throw new InvalidOperationException("Beatmap was not loaded");
ruleset = osu?.Ruleset.Value ?? beatmap.BeatmapInfo.Ruleset; ruleset = Ruleset.Value ?? beatmap.BeatmapInfo.Ruleset;
var rulesetInstance = ruleset.CreateInstance(); var rulesetInstance = ruleset.CreateInstance();
try try
@ -235,7 +241,7 @@ namespace osu.Game.Screens.Play
Ruleset = ruleset Ruleset = ruleset
}; };
scoreProcessor.PopulateScore(score); scoreProcessor.PopulateScore(score);
score.User = RulesetContainer.Replay?.User ?? (Game as OsuGame)?.API?.LocalUser?.Value; score.User = RulesetContainer.Replay?.User ?? api.LocalUser.Value;
Push(new Results(score)); Push(new Results(score));
}); });
} }