From 2417f37e21fe5519024278f8bbf0304e1084cf3f Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 1 May 2010 10:46:56 +0000 Subject: [PATCH] added more debugging for error conditions --- source/glest_game/network/network_message.h | 3 ++- source/glest_game/types/command_type.cpp | 26 ++++++++++++++++--- source/glest_game/types/faction_type.cpp | 18 ++++++++++++- source/glest_game/types/unit_type.cpp | 4 +++ source/glest_game/types/upgrade_type.cpp | 6 ++++- source/glest_game/world/world.cpp | 4 +++ .../platform/common/platform_common.cpp | 2 -- source/shared_lib/sources/util/util.cpp | 14 +++++----- 8 files changed, 62 insertions(+), 15 deletions(-) diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 1e0bcc2bf..187909014 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -186,6 +186,7 @@ private: struct Data{ int8 messageType; uint8 commandCount; + //int8 commandCount; int32 frameCount; NetworkCommand commands[maxCommandCount]; }; @@ -216,7 +217,7 @@ public: class NetworkMessageText: public NetworkMessage{ private: - static const int maxStringSize= 64; + static const int maxStringSize= 128; private: struct Data{ diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index e923b1940..b84045887 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -43,6 +43,8 @@ CommandClass CommandType::getClass() const{ } void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + this->id= id; name= n->getChild("name")->getAttribute("value")->getRestrictedValue(); @@ -66,6 +68,8 @@ void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTr string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); upgradeReqs.push_back(ft->getUpgradeType(name)); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ===================================================== @@ -336,6 +340,8 @@ void BuildCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ } void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + CommandType::load(id, n, dir, tt, ft, ut); //move @@ -379,6 +385,8 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T builtSounds[i]= sound; } } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } string BuildCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ @@ -492,6 +500,8 @@ void RepairCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ void RepairCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + CommandType::load(id, n, dir, tt, ft, ut); //move @@ -508,6 +518,8 @@ void RepairCommandType::load(int id, const XmlNode *n, const string &dir, const const XmlNode *unitNode= unitsNode->getChild("unit", i); repairableUnits.push_back(ft->getUnitType(unitNode->getAttribute("name")->getRestrictedValue())); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } string RepairCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ @@ -558,7 +570,9 @@ void ProduceCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ } void ProduceCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - CommandType::load(id, n, dir, tt, ft, ut); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + CommandType::load(id, n, dir, tt, ft, ut); //produce string skillName= n->getChild("produce-skill")->getAttribute("value")->getRestrictedValue(); @@ -566,6 +580,8 @@ void ProduceCommandType::load(int id, const XmlNode *n, const string &dir, const string producedUnitName= n->getChild("produced-unit")->getAttribute("name")->getRestrictedValue(); producedUnit= ft->getUnitType(producedUnitName); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ @@ -671,7 +687,9 @@ void MorphCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ } void MorphCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - CommandType::load(id, n, dir, tt, ft, ut); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + CommandType::load(id, n, dir, tt, ft, ut); //morph skill string skillName= n->getChild("morph-skill")->getAttribute("value")->getRestrictedValue(); @@ -683,6 +701,8 @@ void MorphCommandType::load(int id, const XmlNode *n, const string &dir, const T //discount discount= n->getChild("discount")->getAttribute("value")->getIntValue(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } string MorphCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 1e59d329d..8c36a1f8b 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -36,6 +36,8 @@ FactionType::FactionType(){ //load a faction, given a directory void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + name= lastDir(dir); Logger::getInstance().add("Faction type: "+ formatString(name), true); @@ -117,6 +119,8 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch music= new StrSound(); music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue()); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } FactionType::~FactionType(){ @@ -131,6 +135,12 @@ const UnitType *FactionType::getUnitType(const string &name) const{ return &unitTypes[i]; } } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] size = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),unitTypes.size()); + for(int i=0; iid= id; string path; @@ -382,6 +384,8 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa catch(const exception &e){ throw runtime_error("Error loading UnitType: " + path + "\n" + e.what()); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ==================== get ==================== diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index ef4072dd2..051cf31f2 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -48,6 +48,8 @@ void UpgradeType::preLoad(const string &dir){ } void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + string path; Logger::getInstance().add("Upgrade type: "+ formatString(name), true); @@ -123,6 +125,8 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio catch(const exception &e){ throw runtime_error("Error loading UpgradeType: "+ dir + "\n" +e.what()); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } string UpgradeType::getReqDesc() const{ diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 90d85c50a..7d0f1f317 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -332,6 +332,8 @@ bool World::toRenderUnit(const Unit *unit) const{ } void World::createUnit(const string &unitName, int factionIndex, const Vec2i &pos){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitName [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); + if(factionIndexgetType(); @@ -352,6 +354,8 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po { throw runtime_error("Invalid faction index in createUnitAtPosition: " + intToStr(factionIndex)); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void World::giveResource(const string &resourceName, int factionIndex, int amount){ diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 2202a1b0e..f86b498a3 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -47,8 +47,6 @@ #include #include - - #include "leak_dumper.h" using namespace Shared::Platform; diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 5bcd957f3..ccf9584ce 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -84,7 +84,7 @@ void SystemFlags::Close() { currentDebugLog.fileStream->close(); } delete currentDebugLog.fileStream; - delete currentDebugLog.mutex; + //delete currentDebugLog.mutex; } currentDebugLog.fileStream = NULL; currentDebugLog.fileStreamOwner = false; @@ -143,7 +143,7 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { currentDebugLog2.fileStream != NULL) { currentDebugLog.fileStream = currentDebugLog2.fileStream; currentDebugLog.fileStreamOwner = false; - currentDebugLog.mutex = currentDebugLog2.mutex; + //currentDebugLog.mutex = currentDebugLog2.mutex; break; } } @@ -189,17 +189,17 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { currentDebugLog.fileStream = new std::ofstream(); currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc); currentDebugLog.fileStreamOwner = true; - currentDebugLog.mutex = new Mutex(); + //currentDebugLog.mutex = new Mutex(); } printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner); - currentDebugLog.mutex->p(); + //currentDebugLog.mutex->p(); (*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n"; (*currentDebugLog.fileStream).flush(); - currentDebugLog.mutex->v(); + //currentDebugLog.mutex->v(); } //printf("Logfile is open [%s]\n",SystemFlags::debugLogFile); @@ -208,12 +208,12 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { assert(currentDebugLog.fileStream != NULL); - currentDebugLog.mutex->p(); + //currentDebugLog.mutex->p(); (*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf; (*currentDebugLog.fileStream).flush(); - currentDebugLog.mutex->v(); + //currentDebugLog.mutex->v(); } // output to console else {