From 7ded9dbda89794012c6f5bb210595217d18caf46 Mon Sep 17 00:00:00 2001 From: godric3 Date: Sat, 27 Oct 2018 18:18:08 +0200 Subject: [PATCH 1/2] Fix crash when generating random map with random number of players --- client/Client.cpp | 2 +- lib/rmg/CMapGenOptions.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/Client.cpp b/client/Client.cpp index 19f25437e..932471c31 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -321,7 +321,7 @@ void CClient::initMapHandler() void CClient::initPlayerInterfaces() { - for(auto & elem : CSH->si->playerInfos) + for(auto & elem : gs->scenarioOps->playerInfos) { PlayerColor color = elem.first; if(!vstd::contains(CSH->getAllClientPlayers(CSH->c->connectionID), color)) diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index 42d3b9319..c52eedef1 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -71,8 +71,13 @@ void CMapGenOptions::setPlayerCount(si8 value) if (compOnlyPlayerCount > possibleCompPlayersCount) setCompOnlyPlayerCount(possibleCompPlayersCount); - if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE) - humanPlayersCount = getPlayerCount() - getCompOnlyPlayerCount(); + if (getPlayerCount() != RANDOM_SIZE) + { + if (getCompOnlyPlayerCount() != RANDOM_SIZE) + humanPlayersCount = getPlayerCount() - getCompOnlyPlayerCount(); + else + humanPlayersCount = getPlayerCount(); + } resetPlayersMap(); } @@ -167,7 +172,10 @@ void CMapGenOptions::resetPlayersMap() auto pc = PlayerColor(color); player.setColor(pc); auto playerType = EPlayerType::AI; - if ((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt) + if (getPlayerCount() != RANDOM_SIZE && color < realPlayersCnt) + { + playerType = EPlayerType::HUMAN; + }else if ((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt) || (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I-compOnlyPlayerCount))) { playerType = EPlayerType::COMP_ONLY; From f563712782b0c346b59ac6731372f0bd7570e284 Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Sun, 28 Oct 2018 16:36:11 +0100 Subject: [PATCH 2/2] fix formatting Co-Authored-By: godric3 --- lib/rmg/CMapGenOptions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index c52eedef1..4de95e678 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -175,7 +175,8 @@ void CMapGenOptions::resetPlayersMap() if (getPlayerCount() != RANDOM_SIZE && color < realPlayersCnt) { playerType = EPlayerType::HUMAN; - }else if ((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt) + } + else if((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt) || (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I-compOnlyPlayerCount))) { playerType = EPlayerType::COMP_ONLY;