From a5281739438f0c4bc38f52ce3a7f57cb980e0f98 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 8 Sep 2017 19:04:24 +0900 Subject: [PATCH] Ensure that WorkingBeatmap's Beatmap is never null Also ensures some extra fields inside Beatmap have non-null defaults. --- osu.Game/Beatmaps/Beatmap.cs | 8 ++++---- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 6 +----- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 4 +--- osu.Game/Beatmaps/WorkingBeatmap.cs | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 82777734bb..15953fcd82 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps public class Beatmap where T : HitObject { - public BeatmapInfo BeatmapInfo; + public BeatmapInfo BeatmapInfo = new BeatmapInfo(); public ControlPointInfo ControlPointInfo = new ControlPointInfo(); public List Breaks = new List(); public readonly List ComboColors = new List @@ -33,7 +33,7 @@ namespace osu.Game.Beatmaps /// /// The HitObjects this Beatmap contains. /// - public List HitObjects; + public List HitObjects = new List(); /// /// Total amount of break time in the beatmap. @@ -44,12 +44,13 @@ namespace osu.Game.Beatmaps /// Constructs a new beatmap. /// /// The original beatmap to use the parameters of. - public Beatmap(Beatmap original = null) + public Beatmap(Beatmap original = null) { BeatmapInfo = original?.BeatmapInfo.DeepClone() ?? BeatmapInfo; ControlPointInfo = original?.ControlPointInfo ?? ControlPointInfo; Breaks = original?.Breaks ?? Breaks; ComboColors = original?.ComboColors ?? ComboColors; + HitObjects = original?.HitObjects ?? HitObjects; } } @@ -65,7 +66,6 @@ namespace osu.Game.Beatmaps public Beatmap(Beatmap original = null) : base(original) { - HitObjects = original?.HitObjects; } } } diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 479f274efb..cc982c7a70 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -7,7 +7,6 @@ using osu.Framework.Audio.Track; using osu.Framework.Graphics.Textures; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; @@ -42,10 +41,7 @@ namespace osu.Game.Beatmaps this.game = game; } - protected override Beatmap GetBeatmap() => new Beatmap - { - HitObjects = new List(), - }; + protected override Beatmap GetBeatmap() => new Beatmap(); protected override Texture GetBackground() => game.Textures.Get(@"Backgrounds/bg4"); diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 234d65eee4..81695c3b5a 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using osu.Game.Rulesets.Objects; namespace osu.Game.Beatmaps.Formats { @@ -21,7 +20,7 @@ namespace osu.Game.Beatmaps.Formats { string line; do { line = stream.ReadLine()?.Trim(); } - while (line != null && line.Length == 0); + while (line != null && line.Length == 0); if (line == null || !decoders.ContainsKey(line)) throw new IOException(@"Unknown file format"); @@ -47,7 +46,6 @@ namespace osu.Game.Beatmaps.Formats { var beatmap = new Beatmap { - HitObjects = new List(), BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata(), diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 462f94ed7c..4797f438d0 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps { if (beatmap != null) return beatmap; - beatmap = GetBeatmap(); + beatmap = GetBeatmap() ?? new Beatmap(); // use the database-backed info. beatmap.BeatmapInfo = BeatmapInfo;