From d24286273b68c0d1d3cd3d79bbfbc0e17dceff67 Mon Sep 17 00:00:00 2001 From: MiroslavR Date: Wed, 28 Jun 2017 22:40:13 +0200 Subject: [PATCH] Prevent respawned references from being added to the scene twice in certain cases (Fixes #3864) --- apps/openmw/mwrender/objects.cpp | 16 +++++++++------- apps/openmw/mwworld/scene.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index d4cbf25fe..f0a3d2e38 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -38,6 +38,8 @@ Objects::~Objects() void Objects::insertBegin(const MWWorld::Ptr& ptr) { + assert(mObjects.find(ptr) == mObjects.end()); + osg::ref_ptr cellnode; CellMap::iterator found = mCellSceneNodes.find(ptr.getCell()); @@ -90,9 +92,8 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b else anim = new CreatureAnimation(ptr, mesh, mResourceSystem); - ptr.getClass().getContainerStore(ptr).setContListener(static_cast(anim.get())); - - mObjects.insert(std::make_pair(ptr, anim)); + if (mObjects.insert(std::make_pair(ptr, anim)).second) + ptr.getClass().getContainerStore(ptr).setContListener(static_cast(anim.get())); } void Objects::insertNPC(const MWWorld::Ptr &ptr) @@ -102,10 +103,11 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr) osg::ref_ptr anim (new NpcAnimation(ptr, osg::ref_ptr(ptr.getRefData().getBaseNode()), mResourceSystem)); - ptr.getClass().getInventoryStore(ptr).setInvListener(anim.get(), ptr); - ptr.getClass().getInventoryStore(ptr).setContListener(anim.get()); - - mObjects.insert(std::make_pair(ptr, anim)); + if (mObjects.insert(std::make_pair(ptr, anim)).second) + { + ptr.getClass().getInventoryStore(ptr).setInvListener(anim.get(), ptr); + ptr.getClass().getInventoryStore(ptr).setContListener(anim.get()); + } } bool Objects::removeObject (const MWWorld::Ptr& ptr) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8da01cc4b..c83165239 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -54,6 +54,12 @@ namespace void addObject(const MWWorld::Ptr& ptr, MWPhysics::PhysicsSystem& physics, MWRender::RenderingManager& rendering) { + if (ptr.getRefData().getBaseNode() || physics.getActor(ptr)) + { + std::cerr << "Warning: Tried to add " << ptr.getCellRef().getRefId() << " to the scene twice" << std::endl; + return; + } + bool useAnim = ptr.getClass().useAnim(); std::string model = ptr.getClass().getModel(ptr); if (useAnim)