1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 13:23:53 +00:00

fix crash on disappeared target

This commit is contained in:
mrcheko 2014-05-18 23:15:22 +04:00
parent e1249f6a31
commit fa14df62b7

View file

@ -141,7 +141,16 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration)
{ {
if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break; if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break;
ESM::Position &targetPos = static_cast<const AiCombat *>(*it)->getTarget().getRefData().getPosition(); MWWorld::Ptr target = static_cast<const AiCombat *>(*it)->getTarget();
// target disappeared (e.g. summoned creatures)
if (target.isEmpty())
{
mPackages.erase(it++);
}
else
{
ESM::Position &targetPos = target.getRefData().getPosition();
float distTo = (Ogre::Vector3(targetPos.pos) - vActorPos).length(); float distTo = (Ogre::Vector3(targetPos.pos) - vActorPos).length();
if (distTo < nearestDist) if (distTo < nearestDist)
@ -150,8 +159,15 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration)
itActualCombat = it; itActualCombat = it;
} }
} }
}
if (mPackages.begin() != itActualCombat) // all targets disappeared
if (nearestDist == std::numeric_limits<float>::max())
{
mDone = true;
return;
}
else if (mPackages.begin() != itActualCombat)
{ {
// move combat package with nearest target to the front // move combat package with nearest target to the front
mPackages.splice(mPackages.begin(), mPackages, itActualCombat); mPackages.splice(mPackages.begin(), mPackages, itActualCombat);