diff --git a/source/glest_game/ai/ai_rule.cpp b/source/glest_game/ai/ai_rule.cpp index f8815c41..f4d67ed1 100644 --- a/source/glest_game/ai/ai_rule.cpp +++ b/source/glest_game/ai/ai_rule.cpp @@ -1090,10 +1090,10 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){ defCt = producersDefaultCommandType[bestIndex][bestCommandTypeIndex]; } - if(ai->outputAIBehaviourToConsole()) printf("mega #2 produceSpecific giveCommand to unit [%s] commandType [%s]\n",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),defCt->getName().c_str()); + if(ai->outputAIBehaviourToConsole()) printf("mega #2 produceSpecific giveCommand to unit [%s] commandType [%s]\n",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),(defCt != NULL ? defCt->getName().c_str() : "n/a")); if(aiInterface->isLogLevelEnabled(4) == true) { char szBuf[8096]=""; - snprintf(szBuf,8096,"mega #2 produceSpecific giveCommand to unit [%s] commandType [%s]",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),defCt->getName().c_str()); + snprintf(szBuf,8096,"mega #2 produceSpecific giveCommand to unit [%s] commandType [%s]",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),(defCt != NULL ? defCt->getName().c_str() : "n/a")); aiInterface->printLog(4, szBuf); } aiInterface->giveCommand(bestIndex, defCt); @@ -1114,10 +1114,10 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){ defCt = producersDefaultCommandType[bestIndex][bestCommandTypeIndex]; } - if(ai->outputAIBehaviourToConsole()) printf("mega #3 produceSpecific giveCommand to unit [%s] commandType [%s]\n",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),defCt->getName().c_str()); + if(ai->outputAIBehaviourToConsole()) printf("mega #3 produceSpecific giveCommand to unit [%s] commandType [%s]\n",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),(defCt != NULL ? defCt->getName().c_str() : "n/a")); if(aiInterface->isLogLevelEnabled(4) == true) { char szBuf[8096]=""; - snprintf(szBuf,8096,"mega #3 produceSpecific giveCommand to unit [%s] commandType [%s]",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),defCt->getName().c_str()); + snprintf(szBuf,8096,"mega #3 produceSpecific giveCommand to unit [%s] commandType [%s]",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),(defCt != NULL ? defCt->getName().c_str() : "n/a")); aiInterface->printLog(4, szBuf); } @@ -1134,10 +1134,10 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){ defCt = producersDefaultCommandType[bestIndex][bestCommandTypeIndex]; } - if(ai->outputAIBehaviourToConsole()) printf("mega #4 produceSpecific giveCommand to unit [%s] commandType [%s]\n",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),defCt->getName().c_str()); + if(ai->outputAIBehaviourToConsole()) printf("mega #4 produceSpecific giveCommand to unit [%s] commandType [%s]\n",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),(defCt != NULL ? defCt->getName().c_str() : "n/a")); if(aiInterface->isLogLevelEnabled(4) == true) { char szBuf[8096]=""; - snprintf(szBuf,8096,"mega #4 produceSpecific giveCommand to unit [%s] commandType [%s]",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),defCt->getName().c_str()); + snprintf(szBuf,8096,"mega #4 produceSpecific giveCommand to unit [%s] commandType [%s]",aiInterface->getMyUnit(bestIndex)->getType()->getName().c_str(),(defCt != NULL ? defCt->getName().c_str() : "n/a")); aiInterface->printLog(4, szBuf); } diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index b85d7d53..0b23487a 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -617,6 +617,9 @@ void Program::setState(ProgramState *programStateNew, bool cleanupOldState) { this->programState= programStateNew; assert(programStateNew != NULL); + if(programStateNew == NULL) { + throw megaglest_runtime_error("programStateNew == NULL"); + } programStateNew->load(); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index e839f794..9d925734 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -1772,7 +1772,7 @@ void UnitUpdater::updateRepair(Unit *unit, int frameIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] rct = %p\n",__FILE__,__FUNCTION__,__LINE__,rct); Unit *repaired = (command != NULL ? map->getCell(command->getPos())->getUnitWithEmptyCellMap(fLand) : NULL); - if(repaired == NULL) { + if(repaired == NULL && command != NULL) { repaired = map->getCell(command->getPos())->getUnit(fLand); } @@ -1891,6 +1891,10 @@ void UnitUpdater::updateRepair(Unit *unit, int frameIndex) { if(unit->getCurrSkill()->getClass() != scRepair || (nextToRepaired == false && peerUnitBuilder == NULL)) { + if(command == NULL) { + throw megaglest_runtime_error("command == NULL"); + } + Vec2i repairPos = command->getPos(); bool startRepairing = (repaired != NULL && rct->isRepairableUnitType(repaired->getType()) && repaired->isDamaged());