From 51ceb068a7b1cdfc0fc2b87203d56d067fec5a55 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 1 Jan 2025 21:00:25 +0000 Subject: [PATCH] Try to handle crash on map selection screen --- client/lobby/CSelectionBase.cpp | 9 ++++++++- client/lobby/OptionsTab.cpp | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client/lobby/CSelectionBase.cpp b/client/lobby/CSelectionBase.cpp index 7b49da41c..d8ebc256d 100644 --- a/client/lobby/CSelectionBase.cpp +++ b/client/lobby/CSelectionBase.cpp @@ -74,7 +74,14 @@ int ISelectionScreenInfo::getCurrentDifficulty() PlayerInfo ISelectionScreenInfo::getPlayerInfo(PlayerColor color) { - return getMapInfo()->mapHeader->players.at(color.getNum()); + auto mapInfo = getMapInfo(); + if (!mapInfo) + throw std::runtime_error("Attempt to get player info for invalid map!"); + + if (!mapInfo->mapHeader) + throw std::runtime_error("Attempt to get player info for invalid map header!"); + + return mapInfo->mapHeader->players.at(color.getNum()); } CSelectionBase::CSelectionBase(ESelectionScreen type) diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index 4d5aa771c..97bb2383b 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -933,6 +933,9 @@ void OptionsTab::SelectedBox::showPopupWindow(const Point & cursorPosition) void OptionsTab::SelectedBox::clickReleased(const Point & cursorPosition) { + if (!SEL) + return; + if(SEL->screenType != ESelectionScreen::newGame) return;