From 8ad7a5c8a298dd887bbc536591e5f2fc25f224b8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Feb 2010 10:09:31 +0000 Subject: [PATCH] Fixed double addition of source node when doing ObserverNodPath::setNodePathTo() Fixed comment in Referenced.cpp --- src/osg/ObserverNodePath.cpp | 45 ++++++++++++++++++++++++++++++++---- src/osg/Referenced.cpp | 2 +- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/osg/ObserverNodePath.cpp b/src/osg/ObserverNodePath.cpp index 0adf40ca5..794197264 100644 --- a/src/osg/ObserverNodePath.cpp +++ b/src/osg/ObserverNodePath.cpp @@ -12,6 +12,7 @@ */ #include +#include using namespace osg; @@ -53,6 +54,32 @@ ObserverNodePath& ObserverNodePath::operator = (const ObserverNodePath& rhs) return *this; } +void ObserverNodePath::setNodePathTo(osg::Node* node) +{ + if (node) + { + NodePathList nodePathList = node->getParentalNodePaths(); + if (nodePathList.empty()) + { + NodePath nodePath; + nodePath.push_back(node); + setNodePath(nodePath); + } + else + { + if (nodePathList[0].empty()) + { + nodePathList[0].push_back(node); + } + setNodePath(nodePathList[0]); + } + } + else + { + clearNodePath(); + } +} + void ObserverNodePath::setNodePath(const osg::NodePath& nodePath) { OpenThreads::ScopedLock lock(_mutex); @@ -89,7 +116,7 @@ bool ObserverNodePath::getRefNodePath(RefNodePath& refNodePath) const refNodePath.push_back(*itr); } - return !refNodePath.empty(); + return true; } bool ObserverNodePath::getNodePath(NodePath& nodePath) const @@ -99,7 +126,7 @@ bool ObserverNodePath::getNodePath(NodePath& nodePath) const OpenThreads::ScopedLock lock(_mutex); if (!_valid) return false; nodePath = _nodePath; - return !nodePath.empty(); + return true; } void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath) @@ -108,12 +135,15 @@ void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath) _clearNodePath(); + //OSG_NOTICE<<"ObserverNodePath["<addObserver(this); } @@ -122,10 +152,12 @@ void ObserverNodePath::_setNodePath(const osg::NodePath& nodePath) void ObserverNodePath::_clearNodePath() { + //OSG_NOTICE<<"ObserverNodePath["<removeObserver(this); } _nodePath.clear(); @@ -148,10 +180,15 @@ bool ObserverNodePath::objectUnreferenced(void* ptr) { _nodePath.erase(itr); - // return true as we wish calling method to remove self from observert set. + //OSG_NOTICE<<"ObserverNodePath["<(_observers); if (os)