From ddb4c42bf540f6002c394858c66de7d5fb052c62 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 19 Oct 2010 22:47:45 +0000 Subject: [PATCH] - added some guard conditions to avoid segfault when resources are harvested quickly --- source/glest_game/world/unit_updater.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 4e82efbe..622f4319 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -609,7 +609,7 @@ void UnitUpdater::updateHarvest(Unit *unit) { if (canHarvestDestPos == true) { unit->setLastHarvestResourceTarget(NULL); - canHarvestDestPos == (map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource() != NULL); + canHarvestDestPos == (map->getSurfaceCell(Map::toSurfCoords(targetPos)) != NULL && map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource() != NULL && map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource()->getType() != NULL); if(canHarvestDestPos == true) { //if it finds resources it starts harvesting unit->setCurrSkill(hct->getHarvestSkillType()); @@ -668,7 +668,7 @@ void UnitUpdater::updateHarvest(Unit *unit) { if (canHarvestDestPos == true) { unit->setLastHarvestResourceTarget(NULL); - canHarvestDestPos == (map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource() != NULL); + canHarvestDestPos == (map->getSurfaceCell(Map::toSurfCoords(targetPos)) != NULL && map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource() != NULL && map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource()->getType() != NULL); if(canHarvestDestPos == true) { //if it finds resources it starts harvesting unit->setCurrSkill(hct->getHarvestSkillType()); @@ -678,7 +678,10 @@ void UnitUpdater::updateHarvest(Unit *unit) { switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: - unit->setLoadType(map->getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->getResource()->getType()); + { + const ResourceType *loadType = map->getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->getResource()->getType(); + unit->setLoadType(loadType); + } break; case pfRoutePlanner: unit->setLoadType(r->getType());