From 3661d62c0332c762a2e0f1fd6018b0b9cc8587df Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 12 Mar 2013 22:50:26 +0000 Subject: [PATCH] - attempt to fix client crash on disconnect --- .../glest_game/network/client_interface.cpp | 24 ++++++++++++++++--- source/glest_game/network/client_interface.h | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 1e951477b..33ab7366d 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -247,7 +247,7 @@ ClientInterface::~ClientInterface() { //printf("B === Client destructor\n"); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - close(); + close(false); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); delete clientSocket; @@ -270,7 +270,14 @@ void ClientInterface::connect(const Ip &ip, int port) { this->ip = ip; this->port = port; + MutexSafeWrapper safeMutex(networkCommandListThreadAccessor,CODE_AT_LINE); + shutdownNetworkCommandListThread(); + delete clientSocket; + clientSocket = NULL; + + safeMutex.ReleaseLock(); + clientSocket= new ClientSocket(); clientSocket->setBlock(false); clientSocket->connect(ip, port); @@ -1747,13 +1754,20 @@ void ClientInterface::quitGame(bool userManuallyQuit) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } -void ClientInterface::close() -{ +void ClientInterface::close(bool lockMutex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] START, clientSocket = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientSocket); + MutexSafeWrapper safeMutex(NULL,CODE_AT_LINE); + if(lockMutex == true) { + safeMutex.setMutex(networkCommandListThreadAccessor,CODE_AT_LINE); + } + shutdownNetworkCommandListThread(); + delete clientSocket; clientSocket= NULL; + safeMutex.ReleaseLock(); + connectedTime = 0; gotIntro = false; @@ -1764,6 +1778,10 @@ void ClientInterface::close() if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } +void ClientInterface::close() { + close(true); +} + void ClientInterface::discoverServers(DiscoveredServersInterface *cb) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); diff --git a/source/glest_game/network/client_interface.h b/source/glest_game/network/client_interface.h index 5c8fcbde5..a346ee32b 100644 --- a/source/glest_game/network/client_interface.h +++ b/source/glest_game/network/client_interface.h @@ -192,6 +192,8 @@ protected: void updateFrame(int *checkFrame); void shutdownNetworkCommandListThread(); bool getNetworkCommand(int frameCount, int currentCachedPendingCommandsIndex); + + void close(bool lockMutex); }; }}//end namespace