Merge pull request #1291 from MiroslavR/respawn_crash

Prevent respawned references from being added to the scene twice
pull/258/head
scrawl 8 years ago committed by GitHub
commit 0d58a77f86

@ -38,6 +38,8 @@ Objects::~Objects()
void Objects::insertBegin(const MWWorld::Ptr& ptr)
{
assert(mObjects.find(ptr) == mObjects.end());
osg::ref_ptr<osg::Group> 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<ActorAnimation*>(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<ActorAnimation*>(anim.get()));
}
void Objects::insertNPC(const MWWorld::Ptr &ptr)
@ -102,10 +103,11 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr)
osg::ref_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(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)

@ -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)

Loading…
Cancel
Save