Properly detach nodes in CopyRigVisitor (Fixes #3234)

pull/912/head
scrawl 9 years ago
parent 82b792f808
commit 0df975a4d7

@ -1458,7 +1458,11 @@ namespace MWRender
PartHolder::~PartHolder() PartHolder::~PartHolder()
{ {
if (mNode.get() && mNode->getNumParents()) 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); mNode->getParent(0)->removeChild(mNode);
}
} }
void PartHolder::unlink() void PartHolder::unlink()

@ -1,6 +1,7 @@
#include "attach.hpp" #include "attach.hpp"
#include <stdexcept> #include <stdexcept>
#include <iostream>
#include <osg/NodeVisitor> #include <osg/NodeVisitor>
#include <osg/Group> #include <osg/Group>
@ -34,14 +35,30 @@ namespace SceneUtil
std::string lowerName = Misc::StringUtils::lowerCase(node.getName()); std::string lowerName = Misc::StringUtils::lowerCase(node.getName());
if ((lowerName.size() >= mFilter.size() && lowerName.compare(0, mFilter.size(), mFilter) == 0) if ((lowerName.size() >= mFilter.size() && lowerName.compare(0, mFilter.size(), mFilter) == 0)
|| (lowerName.size() >= mFilter2.size() && lowerName.compare(0, mFilter2.size(), mFilter2) == 0)) || (lowerName.size() >= mFilter2.size() && lowerName.compare(0, mFilter2.size(), mFilter2) == 0))
{ mToCopy.push_back(&node);
mParent->addChild(&node);
}
else else
traverse(node); traverse(node);
} }
void doCopy()
{
for (std::vector<osg::ref_ptr<osg::Node> >::iterator it = mToCopy.begin(); it != mToCopy.end(); ++it)
{
osg::ref_ptr<osg::Node> 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: private:
typedef std::vector<osg::ref_ptr<osg::Node> > NodeVector;
NodeVector mToCopy;
osg::ref_ptr<osg::Group> mParent; osg::ref_ptr<osg::Group> mParent;
std::string mFilter; std::string mFilter;
std::string mFilter2; std::string mFilter2;
@ -55,6 +72,7 @@ namespace SceneUtil
CopyRigVisitor copyVisitor(handle, filter); CopyRigVisitor copyVisitor(handle, filter);
toAttach->accept(copyVisitor); toAttach->accept(copyVisitor);
copyVisitor.doCopy();
if (handle->getNumChildren() == 1) if (handle->getNumChildren() == 1)
{ {

Loading…
Cancel
Save