From 4dea67cff9b33cedfef6174ab46813a4caab0378 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 19 Dec 2014 19:08:04 -0800 Subject: [PATCH] - attempt to fix thread crash when ending game for network play --- data/glest_game | 2 +- source/glest_game/game/commander.cpp | 13 ++++++++----- source/glest_game/game/game.cpp | 1 + source/glest_game/network/connection_slot.cpp | 5 +++++ source/shared_lib/sources/platform/posix/socket.cpp | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/data/glest_game b/data/glest_game index b1c0f0cc..19119ebb 160000 --- a/data/glest_game +++ b/data/glest_game @@ -1 +1 @@ -Subproject commit b1c0f0cc18cdd2311b581b44e7ae161317438c93 +Subproject commit 19119ebb9c7c91d364c8d413194e476aa815000b diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index b1e1e44c..7895de75 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -770,16 +770,19 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const { MutexSafeWrapper safeMutex(server->getSlotMutex(playerIndex),CODE_AT_LINE); ConnectionSlot *slot = server->getSlot(playerIndex,false); if(slot != NULL) { - safeMutex.ReleaseLock(true); + safeMutex.ReleaseLock(); NetworkMessageQuit networkMessageQuit; slot->sendMessage(&networkMessageQuit); sleep(5); //printf("Sending nctDisconnectNetworkPlayer\n"); - safeMutex.Lock(); - slot = server->getSlot(playerIndex,false); - if(slot != NULL) { - slot->close(); + if(server != NULL) { + MutexSafeWrapper safeMutex2(server->getSlotMutex(playerIndex),CODE_AT_LINE); + slot = server->getSlot(playerIndex,false); + if(slot != NULL) { + safeMutex2.ReleaseLock(); + slot->close(); + } } } } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index d1b92611..0626b462 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -340,6 +340,7 @@ void Game::endGame() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); quitGame(); + sleep(0); Object::setStateCallback(NULL); thisGamePtr = NULL; diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index f7323604..1a18a3a3 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -250,6 +250,11 @@ void ConnectionSlotThread::execute() { //bool socketHasReadData = Socket::hasDataToRead(socket->getSocketId()); bool socketHasReadData = Socket::hasDataToReadWithWait(socketId,150000); + if(getQuitStatus() == true) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + ConnectionSlotEvent eventCopy; eventCopy.eventType = eReceiveSocketData; eventCopy.connectionSlot = this->slotInterface->getSlot(slotIndex,true); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index de12dd36..a5d4b920 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2637,7 +2637,7 @@ int UPNP_Tools::upnp_init(void *param) { //if(devlist != NULL) { // freeUPNPDevlist(devlist); //} - devlist = NULL; + //devlist = NULL; return result; }