[osg-users] CullVisitor object not getting properly deleted

Robert Osfield robert.osfield at gmail.com
Mon May 23 11:01:41 PDT 2016


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


More information about the osg-users mailing list