From 03a10f217aa69a63936f388f228f26a0dfddba60 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 11 Feb 2017 13:39:26 +0100 Subject: [PATCH] Catch exceptions in AiSequence::execute --- apps/openmw/mwmechanics/aisequence.cpp | 38 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 1bd2f98b3..520bacf5a 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -1,6 +1,7 @@ #include "aisequence.hpp" #include +#include #include @@ -229,26 +230,33 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac } } - if (package->execute (actor,characterController,state,duration)) + try { - // Put repeating noncombat AI packages on the end of the stack so they can be used again - if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat())) + if (package->execute (actor,characterController,state,duration)) { - package->reset(); - mPackages.push_back(package->clone()); + // Put repeating noncombat AI packages on the end of the stack so they can be used again + if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat())) + { + package->reset(); + mPackages.push_back(package->clone()); + } + // To account for the rare case where AiPackage::execute() queued another AI package + // (e.g. AiPursue executing a dialogue script that uses startCombat) + std::list::iterator toRemove = + std::find(mPackages.begin(), mPackages.end(), package); + mPackages.erase(toRemove); + delete package; + if (isActualAiPackage(packageTypeId)) + mDone = true; + } + else + { + mDone = false; } - // To account for the rare case where AiPackage::execute() queued another AI package - // (e.g. AiPursue executing a dialogue script that uses startCombat) - std::list::iterator toRemove = - std::find(mPackages.begin(), mPackages.end(), package); - mPackages.erase(toRemove); - delete package; - if (isActualAiPackage(packageTypeId)) - mDone = true; } - else + catch (std::exception& e) { - mDone = false; + std::cerr << "Error during AiSequence::execute: " << e.what() << std::endl; } } }