From 1a85f56fb4820a07c7b9db88386bc652fbc441e4 Mon Sep 17 00:00:00 2001 From: derivator Date: Tue, 18 Oct 2016 17:41:02 +0200 Subject: [PATCH] Partymodes: Fix "Select random" button selecting invalid profiles which would happen if the number of visible profiles matched the number of used profiles or if there were more slots than usable profiles --- VocaluxeLib/Menu/CMenuPartyNameSelection.cs | 3 ++- VocaluxeLib/Menu/CNameSelection.cs | 18 +++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/VocaluxeLib/Menu/CMenuPartyNameSelection.cs b/VocaluxeLib/Menu/CMenuPartyNameSelection.cs index 423d89e8..92527d08 100644 --- a/VocaluxeLib/Menu/CMenuPartyNameSelection.cs +++ b/VocaluxeLib/Menu/CMenuPartyNameSelection.cs @@ -774,7 +774,8 @@ namespace VocaluxeLib.Menu for (int p = 0; p < _NumPlayerTeams[t]; p++) { int profileID = _NameSelections[_NameSelection].GetRandomUnusedProfile(); - _AddPlayer(t, profileID); + if(profileID >= 0) //only add valid profiles + _AddPlayer(t, profileID); } } } diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index 37806b5f..1718d047 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -465,23 +465,11 @@ namespace VocaluxeLib.Menu public int GetRandomUnusedProfile() { - int id = -1; - if (_VisibleProfiles.Count == 0) - return id; + return -1; - if (_VisibleProfiles.Count == _UsedProfiles.Count) - return id; - - while (id == -1) - { - int rand = CBase.Game.GetRandom(_VisibleProfiles.Count); - if (_UsedProfiles.Contains(_VisibleProfiles[rand])) - continue; - id = _VisibleProfiles[rand]; - } - - return id; + int rand = CBase.Game.GetRandom(_VisibleProfiles.Count); + return _VisibleProfiles[rand]; } private void _PrepareTiles()