From 33480b85c85abbc92730e47c6389a725ed8ae4d5 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Thu, 28 Dec 2017 03:35:53 +0100 Subject: [PATCH 1/2] fix for Drawables being empty crashing --- osu.Game/Screens/Select/BeatmapCarousel.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index e877633ab3..d0990d2d12 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -194,7 +194,11 @@ namespace osu.Game.Screens.Select if (!Items.Any()) return; - int originalIndex = Items.IndexOf(selectedBeatmap?.Drawables.First()); + var d = selectedBeatmap?.Drawables.FirstOrDefault(); + if (d == null) + return; + + int originalIndex = Items.IndexOf(d); int currentIndex = originalIndex; // local function to increment the index in the required direction, wrapping over extremities. From e4a8402d3ccf861ccda33665c56a6001a2a84253 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Dec 2017 12:38:40 +0900 Subject: [PATCH 2/2] Use better logic We need to still perform selection if selectedBeatmap itself is null --- osu.Game/Screens/Select/BeatmapCarousel.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index d0990d2d12..b343998e11 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -194,11 +194,14 @@ namespace osu.Game.Screens.Select if (!Items.Any()) return; - var d = selectedBeatmap?.Drawables.FirstOrDefault(); - if (d == null) + DrawableCarouselItem drawable = null; + + if (selectedBeatmap != null && (drawable = selectedBeatmap.Drawables.FirstOrDefault()) == null) + // if the selected beatmap isn't present yet, we can't correctly change selection. + // we can fix this by changing this method to not reference drawables / Items in the first place. return; - int originalIndex = Items.IndexOf(d); + int originalIndex = Items.IndexOf(drawable); int currentIndex = originalIndex; // local function to increment the index in the required direction, wrapping over extremities.