From 1b52445f86baeeb06c5f520b408383b2641dd927 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Mon, 1 May 2017 19:31:46 -0500 Subject: [PATCH] Fix crash when selecting non-existent IDs from database --- osu.Game/Screens/Menu/MainMenu.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index dc4ec92ee2..47f8fd0dfb 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -22,6 +22,8 @@ using osu.Game.Screens.Tournament; using osu.Framework.Input; using OpenTK.Input; using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; namespace osu.Game.Screens.Menu { @@ -74,10 +76,10 @@ namespace osu.Game.Screens.Menu if (!menuMusic) { trackManager = game.Audio.Track; - int choosableBeatmapsetAmmount = beatmaps.Query().Count(); - if (choosableBeatmapsetAmmount > 0) + List choosableBeatmapsets = beatmaps.Query().ToList(); + if (choosableBeatmapsets.Count > 0) { - song = beatmaps.GetWorkingBeatmap(beatmaps.GetWithChildren(RNG.Next(1, choosableBeatmapsetAmmount)).Beatmaps[0]); + song = beatmaps.GetWorkingBeatmap(beatmaps.GetWithChildren(choosableBeatmapsets[RNG.Next(0, choosableBeatmapsets.Count - 1)].ID).Beatmaps[0]); Beatmap = song; } }