fix crash in SongSelect when traversing while zero beatmaps are loaded

This commit is contained in:
Aergwyn 2017-12-23 12:53:11 +01:00
parent ea90c0cf40
commit 1d67746d32
2 changed files with 21 additions and 1 deletions

View File

@ -69,6 +69,7 @@ namespace osu.Game.Tests.Visual
testSorting(); testSorting();
testRemoveAll(); testRemoveAll();
testEmptyTraversal();
} }
private void ensureRandomFetchSuccess() => private void ensureRandomFetchSuccess() =>
@ -103,6 +104,8 @@ namespace osu.Game.Tests.Visual
AddAssert($"{count} {(diff ? "diffs" : "sets")} visible", () => AddAssert($"{count} {(diff ? "diffs" : "sets")} visible", () =>
carousel.Items.Count(s => (diff ? s.Item is CarouselBeatmap : s.Item is CarouselBeatmapSet) && s.Item.Visible) == count); carousel.Items.Count(s => (diff ? s.Item is CarouselBeatmap : s.Item is CarouselBeatmapSet) && s.Item.Visible) == count);
private void checkNoSelection() => AddAssert("Selection is null", () => currentSelection == null);
private void nextRandom() => private void nextRandom() =>
AddStep("select random next", () => AddStep("select random next", () =>
{ {
@ -274,9 +277,23 @@ namespace osu.Game.Tests.Visual
return false; return false;
}, "Remove all"); }, "Remove all");
AddAssert("Selection is null", () => currentSelection == null); checkNoSelection();
} }
private void testEmptyTraversal()
{
advanceSelection(direction: 1, diff: false);
checkNoSelection();
advanceSelection(direction: 1, diff: true);
checkNoSelection();
advanceSelection(direction: -1, diff: false);
checkNoSelection();
advanceSelection(direction: -1, diff: true);
checkNoSelection();
}
private BeatmapSetInfo createTestBeatmapSet(int i) private BeatmapSetInfo createTestBeatmapSet(int i)
{ {

View File

@ -181,6 +181,9 @@ namespace osu.Game.Screens.Select
/// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param> /// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param>
public void SelectNext(int direction = 1, bool skipDifficulties = true) public void SelectNext(int direction = 1, bool skipDifficulties = true)
{ {
if (!Items.Any())
return;
int originalIndex = Items.IndexOf(selectedBeatmap?.Drawables.First()); int originalIndex = Items.IndexOf(selectedBeatmap?.Drawables.First());
int currentIndex = originalIndex; int currentIndex = originalIndex;