From 1e34bc66c169e7d9b8c86e19da8c9279e776cd7c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 10 Nov 2011 21:00:50 +0000 Subject: [PATCH] added a detailed error message to try to hunt down a bug discovered by Elimnator --- source/glest_game/type_instances/faction.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index c9ec8d04..dc560443 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -660,10 +660,19 @@ bool Faction::applyCosts(const ProducibleType *p){ assert(p != NULL); //for each unit cost spend it //pass 2, decrease resources, except negative static costs (ie: farms) - for(int i=0; igetCostCount(); ++i) - { - const ResourceType *rt= p->getCost(i)->getType(); - int cost= p->getCost(i)->getAmount(); + for(int i=0; igetCostCount(); ++i) { + const Resource *r= p->getCost(i); + if(r == NULL) { + char szBuf[1024]=""; + sprintf(szBuf,"cannot apply costs for p [%s] %d of %d costs resource is null",p->getName().c_str(),i,p->getCostCount()); + } + + const ResourceType *rt= r->getType(); + if(rt == NULL) { + char szBuf[1024]=""; + sprintf(szBuf,"cannot apply costs for p [%s] %d of %d costs resourcetype [%s] is null",p->getName().c_str(),i,p->getCostCount(),r->getDescription().c_str()); + } + int cost= r->getAmount(); if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable) { incResourceAmount(rt, -(cost));