From 8d84869432510f7f17025a3747adae3d8b0eae8a Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 5 May 2017 05:24:52 +0200 Subject: [PATCH] Fix commit 8f71b65d38f (don't overwrite the previous user data) This resulted in a crash/corruption because the KeyframeController, for performance reasons, does not check that the expected user data is there and of correct type. (Fixes #3829) --- components/sceneutil/attach.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/components/sceneutil/attach.cpp b/components/sceneutil/attach.cpp index e61b8a6e0..1385f771e 100644 --- a/components/sceneutil/attach.cpp +++ b/components/sceneutil/attach.cpp @@ -81,14 +81,23 @@ namespace SceneUtil std::string mFilter2; }; + void mergeUserData(osg::UserDataContainer* source, osg::Object* target) + { + if (!target->getUserDataContainer()) + target->setUserDataContainer(source); + else + { + for (unsigned int i=0; igetNumUserObjects(); ++i) + target->getUserDataContainer()->addUserObject(source->getUserObject(i)); + } + } + osg::ref_ptr attach(osg::ref_ptr toAttach, osg::Node *master, const std::string &filter, osg::Group* attachNode) { if (dynamic_cast(toAttach.get())) { osg::ref_ptr handle = new osg::Group; - osg::UserDataContainer* udc = toAttach->getUserDataContainer(); - CopyRigVisitor copyVisitor(handle, filter); toAttach->accept(copyVisitor); copyVisitor.doCopy(); @@ -98,13 +107,13 @@ namespace SceneUtil osg::ref_ptr newHandle = handle->getChild(0); handle->removeChild(newHandle); master->asGroup()->addChild(newHandle); - newHandle->setUserDataContainer(udc); + mergeUserData(toAttach->getUserDataContainer(), newHandle); return newHandle; } else { master->asGroup()->addChild(handle); - handle->setUserDataContainer(udc); + handle->setUserDataContainer(toAttach->getUserDataContainer()); return handle; } }