From 7cd40fc7e4015588ab96385fa4e5b7b4a96a2182 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 18 Sep 2010 08:39:21 +0200 Subject: [PATCH] made engine framelistener more crash-resistant --- apps/openmw/engine.cpp | 77 +++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 46cee2e8b..426876f61 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -56,47 +56,54 @@ void OMW::Engine::executeLocalScripts() bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) { - mEnvironment.mFrameDuration = evt.timeSinceLastFrame; - - // global scripts - mEnvironment.mGlobalScripts->run (mEnvironment); - - bool changed = mEnvironment.mWorld->hasCellChanged(); - - // local scripts - executeLocalScripts(); // This does not handle the case where a global script causes a cell - // change, followed by a cell change in a local script during the same - // frame. - - // passing of time - if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) - mEnvironment.mWorld->advanceTime ( - mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600); - - if (changed) // keep change flag for another frame, if cell changed happend in local script - mEnvironment.mWorld->markCellAsUnchanged(); - - // update actors - mEnvironment.mMechanicsManager->update(); - - if (focusFrameCounter++ == focusUpdateFrame) + try { - std::string handle = mEnvironment.mWorld->getFacedHandle(); + mEnvironment.mFrameDuration = evt.timeSinceLastFrame; - std::string name; + // global scripts + mEnvironment.mGlobalScripts->run (mEnvironment); - if (!handle.empty()) + bool changed = mEnvironment.mWorld->hasCellChanged(); + + // local scripts + executeLocalScripts(); // This does not handle the case where a global script causes a cell + // change, followed by a cell change in a local script during the same + // frame. + + // passing of time + if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) + mEnvironment.mWorld->advanceTime ( + mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600); + + if (changed) // keep change flag for another frame, if cell changed happend in local script + mEnvironment.mWorld->markCellAsUnchanged(); + + // update actors + mEnvironment.mMechanicsManager->update(); + + if (focusFrameCounter++ == focusUpdateFrame) { - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + std::string handle = mEnvironment.mWorld->getFacedHandle(); - if (!ptr.isEmpty()) - name = MWWorld::Class::get (ptr).getName (ptr); + std::string name; + + if (!handle.empty()) + { + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + + if (!ptr.isEmpty()) + name = MWWorld::Class::get (ptr).getName (ptr); + } + + if (!name.empty()) + std::cout << "Object: " << name << std::endl; + + focusFrameCounter = 0; } - - if (!name.empty()) - std::cout << "Object: " << name << std::endl; - - focusFrameCounter = 0; + } + catch (const std::exception& e) + { + std::cerr << "Error in framelistener: " << e.what() << std::endl; } return true;