From bd12b10e293ffc82925f41ccee02c38ea7bd3900 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 31 Dec 2010 01:53:16 +0000 Subject: [PATCH] - bugfixes for debuglog filelist which crashes on windows platform on program exit --- source/shared_lib/include/util/util.h | 4 +-- source/shared_lib/sources/util/util.cpp | 44 ++++++++++++++----------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 0d7ea2b5..b7bb8066 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -109,7 +109,7 @@ protected: static string lockfilename; static int lockFileCountIndex; - static std::map debugLogFileList; + static std::map *debugLogFileList; static bool haveSpecialOutputCommandLineOption; public: @@ -122,7 +122,7 @@ public: ~SystemFlags(); static void init(bool haveSpecialOutputCommandLineOption); - static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; } + static SystemFlagsType & getSystemSettingType(DebugType type) { return (*debugLogFileList)[type]; } static size_t httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data); static std::string getHTTP(std::string URL,CURL *handle=NULL, int timeOut=-1); static std::string escapeURL(std::string URL, CURL *handle=NULL); diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 3fcb2008..76794c49 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -39,7 +39,7 @@ using namespace Shared::PlatformCommon; namespace Shared{ namespace Util{ // Init statics -std::map SystemFlags::debugLogFileList; +std::map *SystemFlags::debugLogFileList = NULL; int SystemFlags::lockFile = -1; int SystemFlags::lockFileCountIndex = -1; string SystemFlags::lockfilename = ""; @@ -174,14 +174,17 @@ void SystemFlags::init(bool haveSpecialOutputCommandLineOption) { //printf("SystemFlags::init CALLED, SystemFlags::debugLogFileList.size() = %d\n",SystemFlags::debugLogFileList.size()); SystemFlags::haveSpecialOutputCommandLineOption = haveSpecialOutputCommandLineOption; - if(SystemFlags::debugLogFileList.size() == 0) { - SystemFlags::debugLogFileList[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem); - SystemFlags::debugLogFileList[SystemFlags::debugNetwork] = SystemFlags::SystemFlagsType(SystemFlags::debugNetwork); - SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance); - SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch); - SystemFlags::debugLogFileList[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands); - SystemFlags::debugLogFileList[SystemFlags::debugLUA] = SystemFlags::SystemFlagsType(SystemFlags::debugLUA); - SystemFlags::debugLogFileList[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError); + //if(SystemFlags::debugLogFileList.size() == 0) { + if(SystemFlags::debugLogFileList == NULL) { + SystemFlags::debugLogFileList = new std::map(); + + (*SystemFlags::debugLogFileList)[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem); + (*SystemFlags::debugLogFileList)[SystemFlags::debugNetwork] = SystemFlags::SystemFlagsType(SystemFlags::debugNetwork); + (*SystemFlags::debugLogFileList)[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance); + (*SystemFlags::debugLogFileList)[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch); + (*SystemFlags::debugLogFileList)[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands); + (*SystemFlags::debugLogFileList)[SystemFlags::debugLUA] = SystemFlags::SystemFlagsType(SystemFlags::debugLUA); + (*SystemFlags::debugLogFileList)[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError); } if(threadLogger == NULL) { @@ -247,16 +250,19 @@ void SystemFlags::Close() { threadLogger = NULL; } - if(SystemFlags::debugLogFileList.size() > 0) { + if(SystemFlags::debugLogFileList != NULL) { if(SystemFlags::haveSpecialOutputCommandLineOption == false) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("START Closing logfiles\n"); } - for(std::map::iterator iterMap = SystemFlags::debugLogFileList.begin(); - iterMap != SystemFlags::debugLogFileList.end(); iterMap++) { + for(std::map::iterator iterMap = SystemFlags::debugLogFileList->begin(); + iterMap != SystemFlags::debugLogFileList->end(); iterMap++) { SystemFlags::SystemFlagsType ¤tDebugLog = iterMap->second; currentDebugLog.Close(); } + + delete SystemFlags::debugLogFileList; + SystemFlags::debugLogFileList = NULL; } if(SystemFlags::lockFile != -1) { #ifndef WIN32 @@ -273,7 +279,7 @@ void SystemFlags::Close() { } } - if(SystemFlags::debugLogFileList.size() > 0) { + if(SystemFlags::debugLogFileList != NULL) { if(SystemFlags::haveSpecialOutputCommandLineOption == false) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("END Closing logfiles\n"); } @@ -281,10 +287,10 @@ void SystemFlags::Close() { } void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) { - if(SystemFlags::debugLogFileList.size() == 0) { + if(SystemFlags::debugLogFileList == NULL) { SystemFlags::init(false); } - SystemFlags::SystemFlagsType ¤tDebugLog = SystemFlags::debugLogFileList[type]; + SystemFlags::SystemFlagsType ¤tDebugLog = (*SystemFlags::debugLogFileList)[type]; if(currentDebugLog.enabled == false) { return; } @@ -316,10 +322,10 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) { void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugTime) { - if(SystemFlags::debugLogFileList.size() == 0) { + if(SystemFlags::debugLogFileList == NULL) { SystemFlags::init(false); } - SystemFlags::SystemFlagsType ¤tDebugLog = SystemFlags::debugLogFileList[type]; + SystemFlags::SystemFlagsType ¤tDebugLog = (*SystemFlags::debugLogFileList)[type]; if(currentDebugLog.enabled == false) { return; } @@ -345,8 +351,8 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT // If the file is already open (shared) by another debug type // do not over-write the file but share the stream pointer - for(std::map::iterator iterMap = SystemFlags::debugLogFileList.begin(); - iterMap != SystemFlags::debugLogFileList.end(); iterMap++) { + for(std::map::iterator iterMap = SystemFlags::debugLogFileList->begin(); + iterMap != SystemFlags::debugLogFileList->end(); iterMap++) { SystemFlags::SystemFlagsType ¤tDebugLog2 = iterMap->second; if( iterMap->first != type &&