From cd98dd0b897a8329c864ccbf84e92572c0eb2ddb Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Sun, 13 Aug 2017 17:44:41 +0300 Subject: [PATCH] CGuiHandler: make terminate_cond non-static Static variable might be not yet initialized by the time it's used inside CGuiHandler constructor. This fix let us avoid crash that occur when built with Xcode 8.2.1 --- CMakeLists.txt.autosave.t10925 | 0 CMakeLists.txt.s10925 | 0 client/CPlayerInterface.cpp | 4 ++-- client/CPreGame.cpp | 2 +- client/gui/CGuiHandler.cpp | 5 ++--- client/gui/CGuiHandler.h | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 CMakeLists.txt.autosave.t10925 create mode 100644 CMakeLists.txt.s10925 diff --git a/CMakeLists.txt.autosave.t10925 b/CMakeLists.txt.autosave.t10925 new file mode 100644 index 000000000..e69de29bb diff --git a/CMakeLists.txt.s10925 b/CMakeLists.txt.s10925 new file mode 100644 index 000000000..e69de29bb diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 032aec95a..3fccbb2e8 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -125,7 +125,7 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player) makingTurn = false; showingDialog = new CondSh(false); cingconsole = new CInGameConsole(); - GH.terminate_cond.set(false); + GH.terminate_cond->set(false); firstCall = 1; //if loading will be overwritten in serialize autosaveCount = 0; isAutoFightOn = false; @@ -2196,7 +2196,7 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul { if (adventureInt) { - GH.terminate_cond.setn(true); + GH.terminate_cond->setn(true); adventureInt->deactivate(); if (GH.topInt() == adventureInt) GH.popInt(adventureInt); diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 0881b4284..96f67de71 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -546,7 +546,7 @@ CGPreGame *CGPreGame::create() if(!CGP) CGP = new CGPreGame(); - GH.terminate_cond.set(false); + GH.terminate_cond->set(false); return CGP; } diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index f7c459b92..d8bbd1c0b 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -26,7 +26,6 @@ extern std::queue events; extern boost::mutex eventsM; -CondSh CGuiHandler::terminate_cond(false); boost::thread_specific_ptr inGuiThread; SObjectConstruction::SObjectConstruction(CIntObject *obj) @@ -443,7 +442,7 @@ void CGuiHandler::renderFrame() //in PreGame terminate_cond stay false bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded - while(!terminate_cond.get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate + while(!terminate_cond->get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate boost::this_thread::sleep(boost::posix_time::milliseconds(15)); if(acquiredTheLockOnPim) @@ -481,7 +480,7 @@ CGuiHandler::CGuiHandler() mainFPSmng = new CFramerateManager(48); //do not init CFramerateManager here --AVS - terminate_cond.set(false); + terminate_cond = new CondSh(false); } CGuiHandler::~CGuiHandler() diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index 9bfdd587d..2db719c8a 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -113,7 +113,7 @@ public: static bool amIGuiThread(); static void pushSDLEvent(int type, int usercode = 0); - static CondSh terminate_cond; // confirm termination + CondSh * terminate_cond; // confirm termination }; extern CGuiHandler GH; //global gui handler