Skip to content

Commit 90540cf

Browse files
author
rtri
committed
catch all exceptions in LoadGame
1 parent b3f2c35 commit 90540cf

8 files changed

Lines changed: 67 additions & 35 deletions

File tree

rts/Game/Game.cpp

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@
4141
#include "Rendering/CommandDrawer.h"
4242
#include "Rendering/LineDrawer.h"
4343
#include "Rendering/GlobalRendering.h"
44-
#include "Rendering/Env/Particles/ProjectileDrawer.h"
4544
#include "Rendering/DebugDrawerAI.h"
4645
#include "Rendering/HUDDrawer.h"
4746
#include "Rendering/IconHandler.h"
4847
#include "Rendering/TeamHighlight.h"
4948
#include "Rendering/UnitDrawer.h"
5049
#include "Rendering/Map/InfoTexture/IInfoTextureHandler.h"
51-
#include "Rendering/Textures/ColorMap.h"
5250
#include "Rendering/Textures/NamedTextures.h"
5351
#include "Lua/LuaGaia.h"
5452
#include "Lua/LuaHandle.h"
@@ -93,18 +91,15 @@
9391
#include "Sim/Weapons/WeaponDefHandler.h"
9492
#include "UI/CommandColors.h"
9593
#include "UI/EndGameBox.h"
96-
#include "UI/GameInfo.h"
9794
#include "UI/GameSetupDrawer.h"
9895
#include "UI/GuiHandler.h"
9996
#include "UI/InfoConsole.h"
10097
#include "UI/KeyBindings.h"
10198
#include "UI/KeyCodes.h"
10299
#include "UI/MiniMap.h"
103100
#include "UI/MouseHandler.h"
104-
#include "UI/QuitBox.h"
105101
#include "UI/ResourceBar.h"
106102
#include "UI/SelectionKeyHandler.h"
107-
#include "UI/ShareBox.h"
108103
#include "UI/TooltipConsole.h"
109104
#include "UI/ProfileDrawer.h"
110105
#include "UI/Groups/GroupHandler.h"
@@ -116,9 +111,7 @@
116111
#include "System/myMath.h"
117112
#include "Net/GameServer.h"
118113
#include "Net/Protocol/NetProtocol.h"
119-
#include "System/SpringApp.h"
120114
#include "System/Util.h"
121-
#include "System/Input/KeyInput.h"
122115
#include "System/FileSystem/FileSystem.h"
123116
#include "System/LoadSave/LoadSaveHandler.h"
124117
#include "System/LoadSave/DemoRecorder.h"
@@ -372,7 +365,7 @@ void CGame::AddTimedJobs()
372365
}
373366
}
374367

375-
void CGame::LoadGame(const std::string& mapName, bool threaded)
368+
void CGame::LoadGame(const std::string& mapName)
376369
{
377370
// NOTE:
378371
// this is needed for LuaHandle::CallOut*UpdateCallIn
@@ -385,43 +378,68 @@ void CGame::LoadGame(const std::string& mapName, bool threaded)
385378
bool forcedQuit = false;
386379

387380
try {
388-
LOG("[Game::%s][1] globalQuit=%d threaded=%d", __func__, globalQuit, threaded);
381+
LOG("[Game::%s][1] globalQuit=%d threaded=%d", __func__, globalQuit, !Threading::IsMainThread());
389382

390383
if (!globalQuit) LoadMap(mapName);
391384
if (!globalQuit) LoadDefs();
392385
} catch (const content_error& e) {
393-
LOG("[Game::%s][1] forced quit with exception \"%s\"", __func__, e.what());
386+
LOG_L(L_WARNING, "[Game::%s][1] forced quit with exception \"%s\"", __func__, e.what());
394387

395388
// we can not (yet) do a clean early exit here because the dtor assumes
396389
// all loading stages proceeded normally; just force automatic shutdown
397390
forcedQuit = true;
398391
}
399392

400-
LOG("[Game::%s][2] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
393+
try {
394+
LOG("[Game::%s][2] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
401395

402-
if (!globalQuit) PreLoadSimulation();
403-
if (!globalQuit) PreLoadRendering();
396+
if (!globalQuit) PreLoadSimulation();
397+
if (!globalQuit) PreLoadRendering();
398+
} catch (const content_error& e) {
399+
LOG_L(L_WARNING, "[Game::%s][2] forced quit with exception \"%s\"", __func__, e.what());
400+
forcedQuit = true;
401+
}
404402

405-
LOG("[Game::%s][3] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
403+
try {
404+
LOG("[Game::%s][3] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
406405

407-
if (!globalQuit) PostLoadSimulation();
408-
if (!globalQuit) PostLoadRendering();
406+
if (!globalQuit) PostLoadSimulation();
407+
if (!globalQuit) PostLoadRendering();
408+
} catch (const content_error& e) {
409+
LOG_L(L_WARNING, "[Game::%s][3] forced quit with exception \"%s\"", __func__, e.what());
410+
forcedQuit = true;
411+
}
409412

410-
LOG("[Game::%s][4] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
413+
try {
414+
LOG("[Game::%s][4] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
411415

412-
if (!globalQuit) LoadInterface();
413-
if (!globalQuit) LoadLua();
416+
if (!globalQuit) LoadInterface();
417+
if (!globalQuit) LoadLua();
418+
} catch (const content_error& e) {
419+
LOG_L(L_WARNING, "[Game::%s][4] forced quit with exception \"%s\"", __func__, e.what());
420+
forcedQuit = true;
421+
}
414422

415-
LOG("[Game::%s][5] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
423+
try {
424+
LOG("[Game::%s][5] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
416425

417-
if (!globalQuit) LoadFinalize();
418-
if (!globalQuit) LoadSkirmishAIs();
426+
if (!globalQuit) LoadFinalize();
427+
if (!globalQuit) LoadSkirmishAIs();
428+
} catch (const content_error& e) {
429+
LOG_L(L_WARNING, "[Game::%s][5] forced quit with exception \"%s\"", __func__, e.what());
430+
forcedQuit = true;
431+
}
419432

420-
LOG("[Game::%s][6] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
433+
try {
434+
LOG("[Game::%s][6] globalQuit=%d forcedQuit=%d", __func__, globalQuit, forcedQuit);
421435

422-
if (!globalQuit && saveFile != nullptr) {
423-
loadscreen->SetLoadMessage("Loading game");
424-
saveFile->LoadGame();
436+
if (!globalQuit && saveFile != nullptr) {
437+
loadscreen->SetLoadMessage("Loading Saved Game");
438+
saveFile->LoadGame();
439+
}
440+
} catch (const content_error& e) {
441+
LOG_L(L_WARNING, "[Game::%s][6] forced quit with exception \"%s\"", __func__, e.what());
442+
forcedQuit = true;
425443
}
426444

427445
finishedLoading = true;
@@ -751,7 +769,7 @@ void CGame::PostLoad()
751769
{
752770
GameSetupDrawer::Disable();
753771

754-
if (gameServer) {
772+
if (gameServer != nullptr) {
755773
gameServer->PostLoad(gs->frameNum);
756774
}
757775
}

rts/Game/Game.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CGame : public CGameController
5050
};
5151

5252
public:
53-
void LoadGame(const std::string& mapName, bool threaded);
53+
void LoadGame(const std::string& mapName);
5454

5555
/// show GameEnd-window, calculate mouse movement etc.
5656
void GameEnd(const std::vector<unsigned char>& winningAllyTeams, bool timeout = false);

rts/Game/LoadScreen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void CLoadScreen::Init()
119119
//! Create the Game Loading Thread
120120
if (mtLoading) {
121121
CglFont::threadSafety = true;
122-
gameLoadThread = new COffscreenGLThread(std::bind(&CGame::LoadGame, game, mapName, true));
122+
gameLoadThread = new COffscreenGLThread(std::bind(&CGame::LoadGame, game, mapName));
123123
}
124124

125125
} catch (const opengl_error& gle) {
@@ -131,7 +131,7 @@ void CLoadScreen::Init()
131131

132132
if (!mtLoading) {
133133
LOG("LoadingScreen: single-threaded");
134-
game->LoadGame(mapName, false);
134+
game->LoadGame(mapName);
135135
}
136136
}
137137

rts/Game/PreGame.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,14 @@ void CPreGame::UpdateClientNet()
250250
clientNet->Update();
251251

252252
if (clientNet->CheckTimeout(0, true)) {
253-
LOG_L(L_WARNING, "Server not reachable");
253+
if (CLuaMenuController::ActivateInstance("[PreGame] Server Connection Timeout")) {
254+
delete this;
255+
return;
256+
}
257+
258+
LOG_L(L_WARNING, "[PreGame] Server Connection Timeout");
254259
SetExitCode(1);
260+
255261
gu->globalQuit = true;
256262
return;
257263
}
@@ -276,7 +282,7 @@ void CPreGame::UpdateClientNet()
276282
pckt >> message;
277283

278284
// (re)activate LuaMenu if user failed to connect
279-
if (luaMenuController->Valid() && luaMenuController->Activate(message)) {
285+
if (CLuaMenuController::ActivateInstance(message)) {
280286
delete this;
281287
return;
282288
}

rts/Menu/LuaMenuController.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void CLuaMenuController::Reset()
5454

5555
bool CLuaMenuController::Activate(const std::string& msg)
5656
{
57-
LOG("[LuaMenuController::%s] luaMenu=%p", __func__, luaMenu);
57+
LOG("[LuaMenuController::%s(msg=\"%s\")] luaMenu=%p", __func__, msg.c_str(), luaMenu);
5858

5959
// LuaMenu might have failed to load, making the controller deadweight
6060
if (luaMenu == nullptr)
@@ -68,6 +68,11 @@ bool CLuaMenuController::Activate(const std::string& msg)
6868
return true;
6969
}
7070

71+
bool CLuaMenuController::ActivateInstance(const std::string& msg)
72+
{
73+
return (luaMenuController->Valid() && luaMenuController->Activate(msg));
74+
}
75+
7176
void CLuaMenuController::ResizeEvent()
7277
{
7378
eventHandler.ViewResize();

rts/Menu/LuaMenuController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class CLuaMenuController : public CGameController
1616
void Reset();
1717
bool Activate(const std::string& msg);
1818

19+
static bool ActivateInstance(const std::string& msg);
20+
1921
int KeyReleased(int k) override;
2022
int KeyPressed(int k, bool isRepeat) override;
2123
int TextInput(const std::string& utf8Text) override;

rts/Rendering/Textures/TextureAtlas.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ int CTextureAtlas::AddTexFromFile(std::string name, std::string file)
8181
StringToLowerInPlace(name);
8282

8383
// if the file is already loaded, use that instead
84-
std::string lcFile = StringToLower(file);
84+
const std::string& lcFile = StringToLower(file);
8585
const auto it = files.find(lcFile);
86+
8687
if (it != files.end()) {
8788
MemTex* memtex = it->second;
8889
memtex->names.push_back(name);

rts/System/SpringApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void SpringApp::LoadSpringMenu()
670670
const std::string& startScript = (cfgScript.empty() && CFileHandler::FileExists(vfsScript, SPRING_VFS_PWD_ALL))? vfsScript: cfgScript;
671671

672672
// bypass default menu if we have a valid LuaMenu handler
673-
if (luaMenuController->Valid() && luaMenuController->Activate(""))
673+
if (CLuaMenuController::ActivateInstance(""))
674674
return;
675675

676676
if (FLAGS_oldmenu || startScript.empty()) {

0 commit comments

Comments
 (0)