[osg-users] CullVisitor object not getting properly deleted
Rick Irons
Rick.Irons at mathworks.com
Mon May 23 12:33:01 PDT 2016
Hi Robert,
The code where the static cast is failing is OSG code (openscenegraph\src\osgUtil\CullVisitor.cpp). I believe it is fairly recent code that was added just prior to the release of 3.4.0. Here is the OSG 3.5.1 version of the change… http://trac.openscenegraph.org/projects/osg/changeset/14578#file0
Thanks,
Rick
From: osg-users [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Robert Osfield
Sent: Monday, May 23, 2016 2:02 PM
To: OpenSceneGraph Users <osg-users at lists.openscenegraph.org>
Subject: Re: [osg-users] CullVisitor object not getting properly deleted
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<mailto: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…
[cid:image001.png at 01D1B505.D7E68DD0]
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<mailto: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/5a9b82c3/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/5a9b82c3/attachment-0003.png>
More information about the osg-users
mailing list