From 2e5fd74db0c3f0b6db9a4aafebcc86b9d991c273 Mon Sep 17 00:00:00 2001 From: Allofich Date: Thu, 20 Apr 2017 19:09:38 +0900 Subject: [PATCH] Fix invalid iterator warning --- apps/openmw/mwmechanics/actors.cpp | 14 ++------------ apps/openmw/mwmechanics/aisequence.cpp | 8 ++++---- apps/openmw/mwmechanics/aisequence.hpp | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 1ae0e36a9..2e200d6c3 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -114,9 +114,7 @@ void adjustCommandedActor (const MWWorld::Ptr& actor) } if (!check.mCommanded && hasCommandPackage) - { stats.getAiSequence().erase(it); - } } 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 if ((effects.get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc()) - || (effects.get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc())) - { - for (std::list::const_iterator it = creatureStats.getAiSequence().begin(); it != creatureStats.getAiSequence().end(); ) - { - if ((*it)->getTypeId() == AiPackage::TypeIdCombat) - it = creatureStats.getAiSequence().erase(it); - else - ++it; - } - } + || (effects.get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc())) + creatureStats.getAiSequence().stopCombat(); // Update bound effects // Note: in vanilla MW multiple bound items of the same type can be created by different spells. diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 84c8eca49..125805507 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -96,16 +96,16 @@ std::list::const_iterator AiSequence::end() const return mPackages.end(); } -std::list::const_iterator AiSequence::erase(std::list::const_iterator package) +void AiSequence::erase(std::list::const_iterator package) { // Not sure if manually terminated packages should trigger mDone, probably not? for(std::list::iterator it = mPackages.begin(); it != mPackages.end(); ++it) { if (package == it) { - AiPackage* packagePtr = *it; - delete packagePtr; - return mPackages.erase(it); + delete *it; + mPackages.erase(it); + return; } } throw std::runtime_error("can't find package to erase"); diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index 4f8b542a4..4b6ec156a 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -64,7 +64,7 @@ namespace MWMechanics std::list::const_iterator begin() const; std::list::const_iterator end() const; - std::list::const_iterator erase (std::list::const_iterator package); + void erase (std::list::const_iterator package); /// Returns currently executing AiPackage type /** \see enum AiPackage::TypeId **/