mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-05 05:11:32 +00:00
Fix #6618: Crash due to iterator invalidation
This commit is contained in:
parent
d680870e8f
commit
83be3826ff
1 changed files with 7 additions and 1 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue