1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-06 09:39:49 +00:00

Fix #6618: Crash due to iterator invalidation

This commit is contained in:
ζeh Matt 2022-02-16 18:19:10 +02:00
parent d680870e8f
commit 83be3826ff
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0

View File

@ -309,12 +309,18 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
{ {
if (package->execute(actor, characterController, mAiState, duration)) if (package->execute(actor, characterController, mAiState, duration))
{ {
// Put repeating noncombat AI packages on the end of the stack so they can be used again const auto packageIdx = std::distance(mPackages.begin(), packageIt);
// Put repeating non-combat AI packages on the end of the stack so they can be used again
if (isActualAiPackage(packageTypeId) && package->getRepeat()) if (isActualAiPackage(packageTypeId) && package->getRepeat())
{ {
package->reset(); package->reset();
mPackages.push_back(package->clone()); mPackages.push_back(package->clone());
} }
// Iterator may have been invalidated by push back ensure its correct.
packageIt = mPackages.begin() + packageIdx;
// To account for the rare case where AiPackage::execute() queued another AI package // To account for the rare case where AiPackage::execute() queued another AI package
// (e.g. AiPursue executing a dialogue script that uses startCombat) // (e.g. AiPursue executing a dialogue script that uses startCombat)
erase(packageIt); erase(packageIt);