[osg-users] CullVisitor object not getting properly deleted

Rick Irons Rick.Irons at mathworks.com
Mon May 23 09:45:55 PDT 2016


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...

[cid:image001.png at 01D1B4EE.430210C0]

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160523/fd5aad1f/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 9165 bytes
Desc: image001.png
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160523/fd5aad1f/attachment-0002.png>


More information about the osg-users mailing list