1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 08:53:52 +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,17 +141,33 @@ 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();
float distTo = (Ogre::Vector3(targetPos.pos) - vActorPos).length(); // target disappeared (e.g. summoned creatures)
if (distTo < nearestDist) if (target.isEmpty())
{ {
nearestDist = distTo; mPackages.erase(it++);
itActualCombat = it; }
else
{
ESM::Position &targetPos = target.getRefData().getPosition();
float distTo = (Ogre::Vector3(targetPos.pos) - vActorPos).length();
if (distTo < nearestDist)
{
nearestDist = distTo;
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);