diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 5cf502476a..36feeb7bef 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1458,7 +1458,11 @@ namespace MWRender PartHolder::~PartHolder() { if (mNode.get() && mNode->getNumParents()) + { + if (mNode->getNumParents() > 1) + std::cerr << "Warning: part has multiple parents " << mNode->getNumParents() << " " << mNode.get() << std::endl; mNode->getParent(0)->removeChild(mNode); + } } void PartHolder::unlink() diff --git a/components/sceneutil/attach.cpp b/components/sceneutil/attach.cpp index 8ac0aa9929..1f06e8327b 100644 --- a/components/sceneutil/attach.cpp +++ b/components/sceneutil/attach.cpp @@ -1,6 +1,7 @@ #include "attach.hpp" #include +#include #include #include @@ -34,14 +35,30 @@ namespace SceneUtil std::string lowerName = Misc::StringUtils::lowerCase(node.getName()); if ((lowerName.size() >= mFilter.size() && lowerName.compare(0, mFilter.size(), mFilter) == 0) || (lowerName.size() >= mFilter2.size() && lowerName.compare(0, mFilter2.size(), mFilter2) == 0)) - { - mParent->addChild(&node); - } + mToCopy.push_back(&node); else traverse(node); } + void doCopy() + { + for (std::vector >::iterator it = mToCopy.begin(); it != mToCopy.end(); ++it) + { + osg::ref_ptr node = *it; + if (node->getNumParents() > 1) + std::cerr << "CopyRigVisitor warning: node has multiple parents" << std::endl; + while (node->getNumParents()) + node->getParent(0)->removeChild(node); + + mParent->addChild(node); + } + mToCopy.clear(); + } + private: + typedef std::vector > NodeVector; + NodeVector mToCopy; + osg::ref_ptr mParent; std::string mFilter; std::string mFilter2; @@ -55,6 +72,7 @@ namespace SceneUtil CopyRigVisitor copyVisitor(handle, filter); toAttach->accept(copyVisitor); + copyVisitor.doCopy(); if (handle->getNumChildren() == 1) {