diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 3498ed40b..3a1e6cec0 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -468,11 +468,11 @@ void Faction::applyDiscount(const ProducibleType *p, int discount) void Faction::applyStaticCosts(const ProducibleType *p) { assert(p != NULL); //decrease static resources - for(int i=0; igetCostCount(); ++i) { + for(int i=0; i < p->getCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); //assert(rt != NULL); if(rt == NULL) { - throw runtime_error("rt == NULL - " + p->getName()); + throw runtime_error(string(__FUNCTION__) + " rt == NULL for ProducibleType [" + p->getName() + "] index: " + intToStr(i)); } if(rt->getClass() == rcStatic) { int cost= p->getCost(i)->getAmount(); diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 8ed1b1645..aacd16065 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -363,6 +363,9 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, int amount= resourceNode->getAttribute("amount")->getIntValue(); sortedItems[name] = amount; } + if(sortedItems.size() < costs.size()) { + costs.resize(sortedItems.size()); + } int index = 0; for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { @@ -380,6 +383,10 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, int amount= resourceNode->getAttribute("amount")->getIntValue(); sortedItems[name] = amount; } + if(sortedItems.size() < storedResources.size()) { + storedResources.resize(sortedItems.size()); + } + index = 0; for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) {