Browse Source

VisitObjEngine: avoid crashes if object is no longer visible

This really shouldn't happen, but better safe than sorry
Arseniy Shestakov 6 years ago
parent
commit
f06c8a8725
1 changed files with 5 additions and 1 deletions
  1. 5 1
      AI/VCAI/FuzzyEngines.cpp

+ 5 - 1
AI/VCAI/FuzzyEngines.cpp

@@ -391,7 +391,11 @@ float VisitObjEngine::evaluate(Goals::VisitObj & goal)
 		return 0;
 
 	auto obj = ai->myCb->getObj(ObjectInstanceID(goal.objid));
-
+	if(!obj)
+	{
+		logAi->error("Goals::VisitObj objid " + std::to_string(goal.objid) + " no longer visible, probably goal used for something it's not intended");
+		return -100; // FIXME: Added check when goal was used for hero instead of VisitHero, but crashes are bad anyway
+	}
 
 	boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj);
 	int objValue = 0;