From b6cd75125076c7906ea6ca925a26aa8fa4d84b1e Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 23:05:20 -0800 Subject: [PATCH] - bugfixes on windows platform when some folders and files are missing, do not crash hard. --- source/glest_game/global/core_data.cpp | 2 +- source/glest_game/menu/menu_state_about.cpp | 2 +- source/shared_lib/include/graphics/FileReader.h | 12 ++++++------ source/shared_lib/sources/map/map_preview.cpp | 4 ++-- source/shared_lib/sources/util/leak_dumper.cpp | 2 +- source/shared_lib/sources/util/properties.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 175f917c..4ccc5f31 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -1470,7 +1470,7 @@ void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSe } #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index bc19a36c..15f913bf 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -200,7 +200,7 @@ string MenuStateAbout::loadAdditionalCredits(){ std::cout << buffer << std::endl; file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif } return result; diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h index 9a910987..2b06d7ec 100644 --- a/source/shared_lib/include/graphics/FileReader.h +++ b/source/shared_lib/include/graphics/FileReader.h @@ -171,14 +171,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con if (ret != NULL) { file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; } } file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return NULL; @@ -223,14 +223,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con if (ret != NULL) { file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; } } file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return NULL; } @@ -368,7 +368,7 @@ T* FileReader::read(const string& filepath) const { T* ret = read(file,filepath); file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; @@ -393,7 +393,7 @@ T* FileReader::read(const string& filepath, T* object) const { T* ret = read(file,filepath,object); file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index 63701398..cc9fd782 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -883,7 +883,7 @@ void MapPreview::loadFromFile(const string &path) { } } - fclose(f1); + if(f1) fclose(f1); fileLoaded = true; mapFileLoaded = path; @@ -964,7 +964,7 @@ void MapPreview::saveToFile(const string &path) { } } - fclose(f1); + if(f1) fclose(f1); hasChanged = false; } diff --git a/source/shared_lib/sources/util/leak_dumper.cpp b/source/shared_lib/sources/util/leak_dumper.cpp index 09b9dc55..54799b21 100644 --- a/source/shared_lib/sources/util/leak_dumper.cpp +++ b/source/shared_lib/sources/util/leak_dumper.cpp @@ -63,7 +63,7 @@ void AllocRegistry::dump(const char *path) { fprintf(f, "Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes); fprintf(f, "Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes); - fclose(f); + if(f) fclose(f); printf("Memory leak dump summary at: %s\n",szBuf2); printf("Total leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 254cf2da..6c5fc99f 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -376,7 +376,7 @@ void Properties::save(const string &path){ fileStream.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif }