Hi Rick, The Object that your observer is trying to dynamic_cast<> on is in the throws of being destructed - have a look at the stack trace, I'm not surprised this fails.
Try removing the use of the dynamic_cast<>, replacing it with a static_cast<>. As long as you don't dereference and just use it to double check other arrays the it things should be OK. As a general note though, it's kind odd bit of code. What does you _renderStageMap contain? Just raw C pointers? I suspect the code should probably be redesigned to avoid trying to do tricks like using an custom Observer to do house keeping. Robert. On 23 May 2016 at 17:45, Rick Irons <rick.ir...@mathworks.com> wrote: > Hi all, > > > > I am encountering an issue with a CullVisitor object not being properly > deleted in version 3.4.0. I am encountering this issue when updating from > version 3.0.1. > > > > The source of the problem is a failed Referenced to CullVisitor dynamic > cast that occurs in the code below… > > > > virtual void objectDeleted(void* object) > > { > > osg::Referenced* ref = > reinterpret_cast<osg::Referenced*>(object); > > osgUtil::CullVisitor* cv = > dynamic_cast<osgUtil::CullVisitor*>(ref); > > OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); > > RenderStageMap::iterator itr = _renderStageMap.find(cv); > > if (itr!=_renderStageMap.end()) > > { > > _renderStageMap.erase(cv); > > } > > } > > > > The call stack at the time of the failed cast is the following… > > > > > > The cv pointer is NULL following the cast. My suspicion is that the > dynamic cast is failing because we are in the destructor of our own object > that inherits the OSG CullVisitor object. I tested this suspicion by > confirming that the same dynamic cast will succeed in application code if > done immediately before invoking the destructor of our version of the > CullVisitor. This issue is blocking our update to 3.4.0 since it causes > numerous unit test failures. > > > > Any suggestions on how to address this issue? > > > > I created the hack below to temporary bypass the problem… > > > > virtual void objectDeleted(void* object) > > { > > osg::Referenced* ref = > reinterpret_cast<osg::Referenced*>(object); > > osgUtil::CullVisitor* cv = > dynamic_cast<osgUtil::CullVisitor*>(ref); > > OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); > > if (cv != NULL) > > { > > RenderStageMap::iterator itr = _renderStageMap.find(cv); > > if (itr!=_renderStageMap.end()) > > { > > _renderStageMap.erase(cv); > > } > > } > > else > > { > > for(RenderStageMap::iterator itr = _renderStageMap.begin(); > > itr != _renderStageMap.end(); > > ++itr) > > { > > osg::Referenced* tmpRef = > dynamic_cast<osg::Referenced*>(itr->first); > > if (ref==tmpRef) > > { > > cv = itr->first; > > _renderStageMap.erase(cv); > > break; > > } > > } > > } > > } > > > > Thanks, > > Rick > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org