From 1fbff088e4a59890b274a4aab6a9b0e1d7532887 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 23 Mar 2010 07:59:24 +0000 Subject: [PATCH] Some bugfixing for logfile saving after testing in win32 --- source/glest_game/main/main.cpp | 20 +++++++++++++++---- source/glest_game/menu/menu_state_options.cpp | 4 ++-- source/shared_lib/include/util/util.h | 5 +++++ source/shared_lib/sources/util/util.cpp | 10 +++++++--- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 1b1d4648..3e13013b 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -31,6 +31,8 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ +string debugLogFile = ""; + // ===================================================== // class ExceptionHandler // ===================================================== @@ -39,9 +41,12 @@ class ExceptionHandler: public PlatformExceptionHandler{ public: virtual void handle(){ - string msg = "An error ocurred and Glest will close.\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."; + string msg = "#1 An error ocurred and Glest will close.\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg.c_str()); + Program *program = Program::getInstance(); if(program) { + //SystemFlags::Close(); program->showMessage(msg.c_str()); } @@ -49,15 +54,20 @@ public: } static void handleRuntimeError(const char *msg) { - Program *program = Program::getInstance(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg); + + Program *program = Program::getInstance(); if(program) { + //SystemFlags::Close(); program->showMessage(msg); } else { - message("An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."); + message("#2 An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."); } restoreVideoMode(true); + //SystemFlags::Close(); exit(0); } @@ -73,6 +83,8 @@ public: if(exitApp == true) { restoreVideoMode(true); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg); + //SystemFlags::Close(); exit(0); } @@ -167,7 +179,6 @@ int glestMain(int argc, char** argv){ Program *program= NULL; ExceptionHandler exceptionHandler; exceptionHandler.install( getCrashDumpFileName() ); - string debugLogFile = ""; try{ Config &config = Config::getInstance(); @@ -216,6 +227,7 @@ int glestMain(int argc, char** argv){ } delete mainWindow; + //SystemFlags::Close(); return 0; } diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index ec8dfb4f..4d8d3fcc 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -114,7 +114,7 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): //textures 3d listBoxTextures3D.pushBackItem(lang.get("No")); listBoxTextures3D.pushBackItem(lang.get("Yes")); - listBoxTextures3D.setSelectedItemIndex(clamp(config.getInt("Textures3D"), 0, 1)); + listBoxTextures3D.setSelectedItemIndex(clamp(config.getBool("Textures3D"), false, true)); //textures 3d listBoxUnitParticles.pushBackItem(lang.get("No")); @@ -268,7 +268,7 @@ void MenuStateOptions::saveConfig(){ config.setString("Shadows", Renderer::shadowsToStr(static_cast(index))); config.setString("Filter", listBoxFilter.getSelectedItem()); - config.setInt("Textures3D", listBoxTextures3D.getSelectedItemIndex()); + config.setBool("Textures3D", listBoxTextures3D.getSelectedItemIndex()); config.setBool("UnitParticles", listBoxUnitParticles.getSelectedItemIndex()); config.setInt("MaxLights", listBoxLights.getSelectedItemIndex()+1); config.setString("SoundVolumeFx", listBoxVolumeFx.getSelectedItem()); diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 17038a1f..b00ec429 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -13,6 +13,7 @@ #define _SHARED_UTIL_UTIL_H_ #include +#include using std::string; @@ -20,6 +21,9 @@ namespace Shared{ namespace Util{ class SystemFlags { +protected: + + static std::ofstream fileStream; public: enum DebugType { @@ -32,6 +36,7 @@ public: static const char *debugLogFile; static void OutputDebug(DebugType type, const char *fmt, ...); + static void Close(); }; const string sharedLibVersionString= "v0.4.1"; diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 7ae5af8d..bf44e24c 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include "leak_dumper.h" @@ -25,10 +24,16 @@ using namespace std; namespace Shared{ namespace Util{ - bool SystemFlags::enableDebugText = false; bool SystemFlags::enableNetworkDebugInfo = false; const char * SystemFlags::debugLogFile = NULL; +ofstream SystemFlags::fileStream; + +void SystemFlags::Close() { + if(fileStream.is_open() == true) { + SystemFlags::fileStream.close(); + } +} void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { if((type == debugSystem && SystemFlags::enableDebugText == false) || @@ -41,7 +46,6 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { // Either output to a logfile or if(SystemFlags::debugLogFile != NULL && SystemFlags::debugLogFile[0] != 0) { - static ofstream fileStream; if(fileStream.is_open() == false) { printf("Opening logfile [%s]\n",SystemFlags::debugLogFile); fileStream.open(SystemFlags::debugLogFile, ios_base::out | ios_base::trunc);