Fix invalid iterator warning

0.6.1
Allofich 8 years ago
parent df3b4fe6a5
commit 2e5fd74db0

@ -114,9 +114,7 @@ void adjustCommandedActor (const MWWorld::Ptr& actor)
} }
if (!check.mCommanded && hasCommandPackage) if (!check.mCommanded && hasCommandPackage)
{
stats.getAiSequence().erase(it); stats.getAiSequence().erase(it);
}
} }
void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float& magicka) void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float& magicka)
@ -707,16 +705,8 @@ namespace MWMechanics
// any value of calm > 0 will stop the actor from fighting // any value of calm > 0 will stop the actor from fighting
if ((effects.get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc()) if ((effects.get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc())
|| (effects.get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc())) || (effects.get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc()))
{ creatureStats.getAiSequence().stopCombat();
for (std::list<AiPackage*>::const_iterator it = creatureStats.getAiSequence().begin(); it != creatureStats.getAiSequence().end(); )
{
if ((*it)->getTypeId() == AiPackage::TypeIdCombat)
it = creatureStats.getAiSequence().erase(it);
else
++it;
}
}
// Update bound effects // Update bound effects
// Note: in vanilla MW multiple bound items of the same type can be created by different spells. // Note: in vanilla MW multiple bound items of the same type can be created by different spells.

@ -96,16 +96,16 @@ std::list<AiPackage*>::const_iterator AiSequence::end() const
return mPackages.end(); return mPackages.end();
} }
std::list<AiPackage*>::const_iterator AiSequence::erase(std::list<AiPackage*>::const_iterator package) void AiSequence::erase(std::list<AiPackage*>::const_iterator package)
{ {
// Not sure if manually terminated packages should trigger mDone, probably not? // Not sure if manually terminated packages should trigger mDone, probably not?
for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); ++it) for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
{ {
if (package == it) if (package == it)
{ {
AiPackage* packagePtr = *it; delete *it;
delete packagePtr; mPackages.erase(it);
return mPackages.erase(it); return;
} }
} }
throw std::runtime_error("can't find package to erase"); throw std::runtime_error("can't find package to erase");

@ -64,7 +64,7 @@ namespace MWMechanics
std::list<AiPackage*>::const_iterator begin() const; std::list<AiPackage*>::const_iterator begin() const;
std::list<AiPackage*>::const_iterator end() const; std::list<AiPackage*>::const_iterator end() const;
std::list<AiPackage*>::const_iterator erase (std::list<AiPackage*>::const_iterator package); void erase (std::list<AiPackage*>::const_iterator package);
/// Returns currently executing AiPackage type /// Returns currently executing AiPackage type
/** \see enum AiPackage::TypeId **/ /** \see enum AiPackage::TypeId **/

Loading…
Cancel
Save