From 67a745cdf6849d9554c3432469dc5b146219d32d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 31 Dec 2010 15:50:54 +0100 Subject: [PATCH] workaround for NPC activation crash --- apps/openmw/engine.cpp | 61 ++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index b2b84255a..9e14c119b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -75,8 +75,8 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) std::string effect; - - + + MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayerPos().getPlayer().getCell(); //If the region has changed if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){ @@ -86,7 +86,7 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) total = 0; test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); } - + if(test.soundList.size() > 0) { std::vector::iterator soundIter = test.soundList.begin(); @@ -118,14 +118,14 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) //play sound std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; mEnvironment.mSoundManager->playSound(effect, 20.0, 1.0); - + break; } pos += chance; } } - + //mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0); //printf("REGION: %s\n", test.name); @@ -297,7 +297,7 @@ void OMW::Engine::go() test.name = ""; total = 0; - + std::cout << "Data directory: " << mDataDir << "\n"; @@ -421,36 +421,45 @@ void OMW::Engine::go() void OMW::Engine::activate() { - std::string handle = mEnvironment.mWorld->getFacedHandle(); + // TODO: This is only a workaround. The input dispatcher should catch any exceptions thrown inside + // the input handling functions. Looks like this will require an OpenEngine modification. + try + { + std::string handle = mEnvironment.mWorld->getFacedHandle(); - if (handle.empty()) - return; + if (handle.empty()) + return; - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - if (ptr.isEmpty()) - return; + if (ptr.isEmpty()) + return; - MWScript::InterpreterContext interpreterContext (mEnvironment, - &ptr.getRefData().getLocals(), ptr); + MWScript::InterpreterContext interpreterContext (mEnvironment, + &ptr.getRefData().getLocals(), ptr); - boost::shared_ptr action = - MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), - mEnvironment); + boost::shared_ptr action = + MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), + mEnvironment); - interpreterContext.activate (ptr, action); + interpreterContext.activate (ptr, action); - std::string script = MWWorld::Class::get (ptr).getScript (ptr); + std::string script = MWWorld::Class::get (ptr).getScript (ptr); - if (!script.empty()) - { - mIgnoreLocalPtr = ptr; - mScriptManager->run (script, interpreterContext); - } + if (!script.empty()) + { + mIgnoreLocalPtr = ptr; + mScriptManager->run (script, interpreterContext); + } - if (!interpreterContext.hasActivationBeenHandled()) + if (!interpreterContext.hasActivationBeenHandled()) + { + interpreterContext.executeActivation(); + } + } + catch (const std::exception& e) { - interpreterContext.executeActivation(); + std::cerr << "Activation failed: " << e.what() << std::endl; } }