added more debugging for error conditions

This commit is contained in:
Mark Vejvoda
2010-05-01 10:46:56 +00:00
parent 77fccb8c4c
commit 2417f37e21
8 changed files with 62 additions and 15 deletions

View File

@@ -186,6 +186,7 @@ private:
struct Data{ struct Data{
int8 messageType; int8 messageType;
uint8 commandCount; uint8 commandCount;
//int8 commandCount;
int32 frameCount; int32 frameCount;
NetworkCommand commands[maxCommandCount]; NetworkCommand commands[maxCommandCount];
}; };
@@ -216,7 +217,7 @@ public:
class NetworkMessageText: public NetworkMessage{ class NetworkMessageText: public NetworkMessage{
private: private:
static const int maxStringSize= 64; static const int maxStringSize= 128;
private: private:
struct Data{ struct Data{

View File

@@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // 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){ 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; this->id= id;
name= n->getChild("name")->getAttribute("value")->getRestrictedValue(); 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(); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue();
upgradeReqs.push_back(ft->getUpgradeType(name)); 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){ 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); CommandType::load(id, n, dir, tt, ft, ut);
//move //move
@@ -379,6 +385,8 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T
builtSounds[i]= sound; builtSounds[i]= sound;
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
string BuildCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ 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){ 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); CommandType::load(id, n, dir, tt, ft, ut);
//move //move
@@ -508,6 +518,8 @@ void RepairCommandType::load(int id, const XmlNode *n, const string &dir, const
const XmlNode *unitNode= unitsNode->getChild("unit", i); const XmlNode *unitNode= unitsNode->getChild("unit", i);
repairableUnits.push_back(ft->getUnitType(unitNode->getAttribute("name")->getRestrictedValue())); 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{ 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){ 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 //produce
string skillName= n->getChild("produce-skill")->getAttribute("value")->getRestrictedValue(); 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(); string producedUnitName= n->getChild("produced-unit")->getAttribute("name")->getRestrictedValue();
producedUnit= ft->getUnitType(producedUnitName); producedUnit= ft->getUnitType(producedUnitName);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ 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){ 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 //morph skill
string skillName= n->getChild("morph-skill")->getAttribute("value")->getRestrictedValue(); 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
discount= n->getChild("discount")->getAttribute("value")->getIntValue(); 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{ string MorphCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{

View File

@@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
@@ -36,6 +36,8 @@ FactionType::FactionType(){
//load a faction, given a directory //load a faction, given a directory
void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum){ 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); name= lastDir(dir);
Logger::getInstance().add("Faction type: "+ formatString(name), true); 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= new StrSound();
music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue()); music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue());
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
FactionType::~FactionType(){ FactionType::~FactionType(){
@@ -131,6 +135,12 @@ const UnitType *FactionType::getUnitType(const string &name) const{
return &unitTypes[i]; 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; i<unitTypes.size();i++){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,unitTypes[i].getName().c_str());
}
throw runtime_error("Unit not found: "+name); throw runtime_error("Unit not found: "+name);
} }
@@ -140,6 +150,12 @@ const UpgradeType *FactionType::getUpgradeType(const string &name) const{
return &upgradeTypes[i]; return &upgradeTypes[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; i<upgradeTypes.size();i++){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,upgradeTypes[i].getName().c_str());
}
throw runtime_error("Upgrade not found: "+name); throw runtime_error("Upgrade not found: "+name);
} }

View File

@@ -100,6 +100,8 @@ void UnitType::preLoad(const string &dir){
void UnitType::load(int id,const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){ void UnitType::load(int id,const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->id= id; this->id= id;
string path; string path;
@@ -382,6 +384,8 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
catch(const exception &e){ catch(const exception &e){
throw runtime_error("Error loading UnitType: " + path + "\n" + e.what()); throw runtime_error("Error loading UnitType: " + path + "\n" + e.what());
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
// ==================== get ==================== // ==================== get ====================

View File

@@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // 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){ 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; string path;
Logger::getInstance().add("Upgrade type: "+ formatString(name), true); 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){ catch(const exception &e){
throw runtime_error("Error loading UpgradeType: "+ dir + "\n" +e.what()); 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{ string UpgradeType::getReqDesc() const{

View File

@@ -332,6 +332,8 @@ bool World::toRenderUnit(const Unit *unit) const{
} }
void World::createUnit(const string &unitName, int factionIndex, const Vec2i &pos){ 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(factionIndex<factions.size()){ if(factionIndex<factions.size()){
Faction* faction= &factions[factionIndex]; Faction* faction= &factions[factionIndex];
const FactionType* ft= faction->getType(); const FactionType* ft= faction->getType();
@@ -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)); 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){ void World::giveResource(const string &resourceName, int factionIndex, int amount){

View File

@@ -47,8 +47,6 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include "leak_dumper.h" #include "leak_dumper.h"
using namespace Shared::Platform; using namespace Shared::Platform;

View File

@@ -84,7 +84,7 @@ void SystemFlags::Close() {
currentDebugLog.fileStream->close(); currentDebugLog.fileStream->close();
} }
delete currentDebugLog.fileStream; delete currentDebugLog.fileStream;
delete currentDebugLog.mutex; //delete currentDebugLog.mutex;
} }
currentDebugLog.fileStream = NULL; currentDebugLog.fileStream = NULL;
currentDebugLog.fileStreamOwner = false; currentDebugLog.fileStreamOwner = false;
@@ -143,7 +143,7 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
currentDebugLog2.fileStream != NULL) { currentDebugLog2.fileStream != NULL) {
currentDebugLog.fileStream = currentDebugLog2.fileStream; currentDebugLog.fileStream = currentDebugLog2.fileStream;
currentDebugLog.fileStreamOwner = false; currentDebugLog.fileStreamOwner = false;
currentDebugLog.mutex = currentDebugLog2.mutex; //currentDebugLog.mutex = currentDebugLog2.mutex;
break; break;
} }
} }
@@ -189,17 +189,17 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
currentDebugLog.fileStream = new std::ofstream(); currentDebugLog.fileStream = new std::ofstream();
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc); currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc);
currentDebugLog.fileStreamOwner = true; 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); 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) << "Starting Mega-Glest logging for type: " << type << "\n";
(*currentDebugLog.fileStream).flush(); (*currentDebugLog.fileStream).flush();
currentDebugLog.mutex->v(); //currentDebugLog.mutex->v();
} }
//printf("Logfile is open [%s]\n",SystemFlags::debugLogFile); //printf("Logfile is open [%s]\n",SystemFlags::debugLogFile);
@@ -208,12 +208,12 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
assert(currentDebugLog.fileStream != NULL); assert(currentDebugLog.fileStream != NULL);
currentDebugLog.mutex->p(); //currentDebugLog.mutex->p();
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf; (*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
(*currentDebugLog.fileStream).flush(); (*currentDebugLog.fileStream).flush();
currentDebugLog.mutex->v(); //currentDebugLog.mutex->v();
} }
// output to console // output to console
else { else {