From 09f7eecf0636d06bb6432ca6635d8154f38c1ef3 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 20 Aug 2010 21:06:20 +0000 Subject: [PATCH] - fix a thread synch issue in the custom game menu --- source/glest_game/menu/menu_state_custom_game.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 9e8fcd1ea..4d0bd4e49 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1172,8 +1172,14 @@ void MenuStateCustomGame::simpleTask() { bool broadCastSettings = needToBroadcastServerSettings; needToBroadcastServerSettings=false; + bool hasClientConnection = false; + if(broadCastSettings) { + ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); + hasClientConnection = serverInterface->hasClientConnection(); + } + bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval); - safeMutex.ReleaseLock(); + safeMutex.ReleaseLock(true); if(republish == true) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1216,7 +1222,7 @@ void MenuStateCustomGame::simpleTask() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(serverInterface->hasClientConnection() == true) { + if(hasClientConnection == true) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); GameSettings gameSettings; @@ -1224,8 +1230,10 @@ void MenuStateCustomGame::simpleTask() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + safeMutex.Lock(); serverInterface->setGameSettings(&gameSettings); serverInterface->broadcastGameSetup(&gameSettings); + safeMutex.ReleaseLock(true); } } @@ -1235,7 +1243,10 @@ void MenuStateCustomGame::simpleTask() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] Sending nmtPing to clients\n",__FILE__,__FUNCTION__,__LINE__); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL)); + + safeMutex.Lock(); serverInterface->broadcastPing(&msg); + safeMutex.ReleaseLock(true); } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);