- added some guard conditions to avoid segfault when resources are harvested quickly

This commit is contained in:
Mark Vejvoda 2010-10-19 22:47:45 +00:00
parent 913df7ec3b
commit ddb4c42bf5
1 changed files with 6 additions and 3 deletions

View File

@ -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());