From dfa9f7cb77e8070036c9229da8e591e3d6006bdd Mon Sep 17 00:00:00 2001 From: Bo Svensson <90132211+bosvensson1@users.noreply.github.com> Date: Sun, 5 Sep 2021 10:24:22 +0000 Subject: [PATCH] attach.cpp [ci skip] --- components/sceneutil/attach.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/components/sceneutil/attach.cpp b/components/sceneutil/attach.cpp index 4f947a8fcd..448b16c6f0 100644 --- a/components/sceneutil/attach.cpp +++ b/components/sceneutil/attach.cpp @@ -98,17 +98,17 @@ namespace SceneUtil } } - osg::ref_ptr attach(osg::ref_ptr toAttach, osg::Node *master, const std::string &filter, osg::Group* attachNode) + osg::ref_ptr attach(osg::ref_ptr toAttach, osg::Node *master, const std::string &filter, osg::Group* attachNode) { - if (dynamic_cast(toAttach.get())) + if (dynamic_cast(toAttach.get())) { osg::ref_ptr handle = new osg::Group; CopyRigVisitor copyVisitor(handle, filter); - toAttach->accept(copyVisitor); + const_cast(toAttach.get())->accept(copyVisitor); copyVisitor.doCopy(); - if (handle->getNumChildren() == 1 && handle->getChild(0)->referenceCount() == 1) + if (handle->getNumChildren() == 1) { osg::ref_ptr newHandle = handle->getChild(0); handle->removeChild(newHandle); @@ -126,9 +126,9 @@ namespace SceneUtil else { CopyOp copyOp; - toAttach = osg::clone(toAttach, copyOp); + osg::ref_ptr clonedToAttach = osg::clone(toAttach, copyOp); FindByNameVisitor findBoneOffset("BoneOffset"); - toAttach->accept(findBoneOffset); + clonedToAttach->accept(findBoneOffset); osg::ref_ptr trans; @@ -171,19 +171,12 @@ namespace SceneUtil if (trans) { attachNode->addChild(trans); - trans->addChild(toAttach); + trans->addChild(clonedToAttach); return trans; } - else if (toAttach->referenceCount() > 1) - { - osg::ref_ptr group = new osg::Group; - group->addChild(toAttach); - attachNode->addChild(group); - return group; - } else { - attachNode->addChild(toAttach); + attachNode->addChild(clonedToAttach); return toAttach; } }