From d5940193a2dce5dd5e35568b0784c624f1117500 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Oct 2020 19:55:20 +0900 Subject: [PATCH] Ensure visible items is greater than zero before trying to display a range --- osu.Game/Screens/Select/BeatmapCarousel.cs | 49 ++++++++++++---------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 92abec0eee..83631fd383 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -590,36 +590,39 @@ namespace osu.Game.Screens.Select { displayedRange = newDisplayRange; - var toDisplay = visibleItems.GetRange(displayedRange.first, displayedRange.last - displayedRange.first + 1); - - foreach (var panel in ScrollableContent.Children) + if (visibleItems.Count > 0) { - if (toDisplay.Remove(panel.Item)) + var toDisplay = visibleItems.GetRange(displayedRange.first, displayedRange.last - displayedRange.first + 1); + + foreach (var panel in ScrollableContent.Children) { - // panel already displayed. - continue; + if (toDisplay.Remove(panel.Item)) + { + // panel already displayed. + continue; + } + + // panel loaded as drawable but not required by visible range. + // remove but only if too far off-screen + if (panel.Y + panel.DrawHeight < visibleUpperBound - distance_offscreen_before_unload || panel.Y > visibleBottomBound + distance_offscreen_before_unload) + { + // may want a fade effect here (could be seen if a huge change happens, like a set with 20 difficulties becomes selected). + panel.ClearTransforms(); + panel.Expire(); + } } - // panel loaded as drawable but not required by visible range. - // remove but only if too far off-screen - if (panel.Y + panel.DrawHeight < visibleUpperBound - distance_offscreen_before_unload || panel.Y > visibleBottomBound + distance_offscreen_before_unload) + // Add those items within the previously found index range that should be displayed. + foreach (var item in toDisplay) { - // may want a fade effect here (could be seen if a huge change happens, like a set with 20 difficulties becomes selected). - panel.ClearTransforms(); - panel.Expire(); + var panel = setPool.Get(p => p.Item = item); + + panel.Depth = item.CarouselYPosition; + panel.Y = item.CarouselYPosition; + + ScrollableContent.Add(panel); } } - - // Add those items within the previously found index range that should be displayed. - foreach (var item in toDisplay) - { - var panel = setPool.Get(p => p.Item = item); - - panel.Depth = item.CarouselYPosition; - panel.Y = item.CarouselYPosition; - - ScrollableContent.Add(panel); - } } // Finally, if the filtered items have changed, animate drawables to their new locations.