From 162e183b36721e0aa3520dd80db1ebc19fbe7f7c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Jan 2017 16:01:49 +0900 Subject: [PATCH] Fix some nullrefs when running visualtests with no maps loaded. --- osu.Desktop.VisualTests/Tests/TestCasePlayer.cs | 4 +++- osu.Game/Beatmaps/Drawables/BeatmapBackgroundSprite.cs | 3 ++- osu.Game/Beatmaps/WorkingBeatmap.cs | 2 ++ osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs index 9e3ad1bbc8..3be8c83299 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs @@ -29,7 +29,9 @@ namespace osu.Desktop.VisualTests.Tests [BackgroundDependencyLoader] private void load(BeatmapDatabase db) { - beatmap = db.GetWorkingBeatmap(db.Query().Where(b => b.Mode == PlayMode.Osu).FirstOrDefault()); + var beatmapInfo = db.Query().Where(b => b.Mode == PlayMode.Osu).FirstOrDefault(); + if (beatmapInfo != null) + beatmap = db.GetWorkingBeatmap(beatmapInfo); } public override void Reset() diff --git a/osu.Game/Beatmaps/Drawables/BeatmapBackgroundSprite.cs b/osu.Game/Beatmaps/Drawables/BeatmapBackgroundSprite.cs index e90829873f..f8cec43f14 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapBackgroundSprite.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapBackgroundSprite.cs @@ -18,7 +18,8 @@ namespace osu.Game.Beatmaps.Drawables [BackgroundDependencyLoader] private void load(OsuGameBase game) { - Texture = working.Background; + if (working.Background != null) + Texture = working.Background; } } } diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 9184607398..a898465610 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -30,6 +30,8 @@ namespace osu.Game.Beatmaps { if (background != null) return background; + if (BeatmapInfo.Metadata?.BackgroundFile == null) return null; + try { using (var reader = GetReader()) diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 7ce71acf3e..58f39013a8 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -56,8 +56,8 @@ namespace osu.Game.Modes.Objects.Drawables [BackgroundDependencyLoader] private void load(AudioManager audio) { - string hitType = (HitObject.Sample.Type == SampleType.None ? SampleType.Normal : HitObject.Sample.Type).ToString().ToLower(); - string sampleSet = HitObject.Sample.Set.ToString().ToLower(); + string hitType = ((HitObject.Sample?.Type ?? SampleType.None) == SampleType.None ? SampleType.Normal : HitObject.Sample.Type).ToString().ToLower(); + string sampleSet = (HitObject.Sample?.Set ?? SampleSet.Normal).ToString().ToLower(); sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}"); }