Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-27 Thread Rick Irons
Hi Robert,

Your most recent changes addressed the crash we were encountering.  Thanks for 
looking into this issue.

Rick

-Original Message-
From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf 
Of Robert Osfield
Sent: Friday, May 27, 2016 4:50 AM
To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org>
Subject: Re: [osg-users] CullVisitor object not getting properly deleted

Hi Rick,

Just tried, static_cast<> isn't usable in this instance thank to the use of 
virtual inheritance.

So the solution I have gone for is refactor the RenderStageCache so that it 
uses a map<Referenced*, ref_ptr> in place of map<CullVisitor*, 
ref_ptr>, this means the cast happens when the map is set up and 
no dynamic_cast<> need be done anywhere.

The changes are:

diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 
d198b78..3112cdf 100644
--- a/src/osgUtil/CullVisitor.cpp
+++ b/src/osgUtil/CullVisitor.cpp
@@ -1368,7 +1368,7 @@ class RenderStageCache : public osg::Object, public 
osg::Observer  {
 public:

-typedef std::map<CullVisitor*, osg::ref_ptr >
RenderStageMap;
+typedef std::map<osg::Referenced*, osg::ref_ptr
> RenderStageMap;

 RenderStageCache() {}
 RenderStageCache(const RenderStageCache&, const osg::CopyOp&) {} @@ 
-1387,18 +1387,17 @@ class RenderStageCache : public osg::Object, public 
osg::Observer
 virtual void objectDeleted(void* object)
 {
 osg::Referenced* ref = reinterpret_cast<osg::Referenced*>(object);
-osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*>(ref);

 OpenThreads::ScopedLock lock(_mutex);

-RenderStageMap::iterator itr = _renderStageMap.find(cv);
+RenderStageMap::iterator itr = _renderStageMap.find(ref);
 if (itr!=_renderStageMap.end())
 {
 _renderStageMap.erase(itr);
 }
 }

-void setRenderStage(CullVisitor* cv, RenderStage* rs)
+void setRenderStage(osg::Referenced* cv, RenderStage* rs)
 {
 OpenThreads::ScopedLock lock(_mutex);
 RenderStageMap::iterator itr = _renderStageMap.find(cv); @@ 
-1414,7 +1413,7 @@ class RenderStageCache : public osg::Object, public 
osg::Observer

 }

-RenderStage* getRenderStage(osgUtil::CullVisitor* cv)
+RenderStage* getRenderStage(osg::Referenced* cv)
 {
 OpenThreads::ScopedLock lock(_mutex);
 RenderStageMap::iterator itr = _renderStageMap.find(cv);


I have checked this fix into OSG master and 3.4 branch.  Commit is
110cf56..31592d2

Could you let me know how this works out, if it fails I'm afraid I'll need a 
small test example to reproduce it as the osgoi and osgprerender examples I'm 
using are working 100% OK.

Robert.

On 27 May 2016 at 09:01, Robert Osfield <robert.osfi...@gmail.com> wrote:
> Hi Rick,
>
> As general note, use of a C pointer to scene graph objects include the 
> CullVisitor should generally be avoided, it's only safe for small 
> blocks of code where you know that the objects will remain in memory 
> at all times during the block.  Instead you should use ref_ptr<> to 
> make sure it's lifetime is correct - if in doubt use ref_ptr<>.
>
> I will have a look at the use of dynamic_cast<> again.  I had to keep 
> it in there because the pointer to the Referenced base class isn't 
> castable directly to a CullVsititor as CullVisitor uses virtual 
> inheritance.
>
> Robert.
>
>
> On 26 May 2016 at 22:04, Rick Irons <rick.ir...@mathworks.com> wrote:
>> Hi Robert,
>>
>>
>>
>> Unfortunately the fix didn't address the crash I am encountering.  
>> The issue of the dynamic cast in objectDeleted()
>> (\openscenegraph\src\osgUtil\CullVisitor.cpp) failing remains...
>>
>>
>>
>> virtual void objectDeleted(void* object)
>>
>> {
>>
>> osg::Referenced* ref =
>> reinterpret_cast<osg::Referenced*>(object);
>>
>> osgUtil::CullVisitor* cv = 
>> dynamic_cast<osgUtil::CullVisitor*>(ref);
>>
>>
>>
>> OpenThreads::ScopedLock lock(_mutex);
>>
>>
>>
>> RenderStageMap::iterator itr = _renderStageMap.find(cv);
>>
>> if (itr!=_renderStageMap.end())
>>
>> {
>>
>> _renderStageMap.erase(itr);
>>
>> }
>>
>> }
>>
>>
>>
>> I was going to define our object that inherits from the CullVisitor 
>> as an osg::ref_ptr.  Perhaps doing so will delay the freeing of the 
>> CullVisitor object 

Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-27 Thread Robert Osfield
Hi Rick,

Just tried, static_cast<> isn't usable in this instance thank to the
use of virtual inheritance.

So the solution I have gone for is refactor the RenderStageCache so
that it uses a map<Referenced*, ref_ptr> in place of
map<CullVisitor*, ref_ptr>, this means the cast happens
when the map is set up and no dynamic_cast<> need be done anywhere.

The changes are:

diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp
index d198b78..3112cdf 100644
--- a/src/osgUtil/CullVisitor.cpp
+++ b/src/osgUtil/CullVisitor.cpp
@@ -1368,7 +1368,7 @@ class RenderStageCache : public osg::Object,
public osg::Observer
 {
 public:

-typedef std::map<CullVisitor*, osg::ref_ptr >
RenderStageMap;
+typedef std::map<osg::Referenced*, osg::ref_ptr
> RenderStageMap;

 RenderStageCache() {}
 RenderStageCache(const RenderStageCache&, const osg::CopyOp&) {}
@@ -1387,18 +1387,17 @@ class RenderStageCache : public osg::Object,
public osg::Observer
 virtual void objectDeleted(void* object)
 {
 osg::Referenced* ref = reinterpret_cast<osg::Referenced*>(object);
-osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*>(ref);

 OpenThreads::ScopedLock lock(_mutex);

-RenderStageMap::iterator itr = _renderStageMap.find(cv);
+RenderStageMap::iterator itr = _renderStageMap.find(ref);
 if (itr!=_renderStageMap.end())
 {
 _renderStageMap.erase(itr);
 }
 }

-void setRenderStage(CullVisitor* cv, RenderStage* rs)
+void setRenderStage(osg::Referenced* cv, RenderStage* rs)
 {
 OpenThreads::ScopedLock lock(_mutex);
 RenderStageMap::iterator itr = _renderStageMap.find(cv);
@@ -1414,7 +1413,7 @@ class RenderStageCache : public osg::Object,
public osg::Observer

 }

-RenderStage* getRenderStage(osgUtil::CullVisitor* cv)
+RenderStage* getRenderStage(osg::Referenced* cv)
 {
 OpenThreads::ScopedLock lock(_mutex);
 RenderStageMap::iterator itr = _renderStageMap.find(cv);


I have checked this fix into OSG master and 3.4 branch.  Commit is
110cf56..31592d2

Could you let me know how this works out, if it fails I'm afraid I'll
need a small test example to reproduce it as the osgoi and
osgprerender examples I'm using are working 100% OK.

Robert.

On 27 May 2016 at 09:01, Robert Osfield <robert.osfi...@gmail.com> wrote:
> Hi Rick,
>
> As general note, use of a C pointer to scene graph objects include the
> CullVisitor should generally be avoided, it's only safe for small
> blocks of code where you know that the objects will remain in memory
> at all times during the block.  Instead you should use ref_ptr<> to
> make sure it's lifetime is correct - if in doubt use ref_ptr<>.
>
> I will have a look at the use of dynamic_cast<> again.  I had to keep
> it in there because the pointer to the Referenced base class isn't
> castable directly to a CullVsititor as CullVisitor uses virtual
> inheritance.
>
> Robert.
>
>
> On 26 May 2016 at 22:04, Rick Irons <rick.ir...@mathworks.com> wrote:
>> Hi Robert,
>>
>>
>>
>> Unfortunately the fix didn't address the crash I am encountering.  The issue
>> of the dynamic cast in objectDeleted()
>> (\openscenegraph\src\osgUtil\CullVisitor.cpp) failing remains...
>>
>>
>>
>> virtual void objectDeleted(void* object)
>>
>> {
>>
>> osg::Referenced* ref =
>> reinterpret_cast<osg::Referenced*>(object);
>>
>> osgUtil::CullVisitor* cv =
>> dynamic_cast<osgUtil::CullVisitor*>(ref);
>>
>>
>>
>> OpenThreads::ScopedLock lock(_mutex);
>>
>>
>>
>> RenderStageMap::iterator itr = _renderStageMap.find(cv);
>>
>> if (itr!=_renderStageMap.end())
>>
>> {
>>
>> _renderStageMap.erase(itr);
>>
>> }
>>
>> }
>>
>>
>>
>> I was going to define our object that inherits from the CullVisitor as an
>> osg::ref_ptr.  Perhaps doing so will delay the freeing of the CullVisitor
>> object long enough within the CullVisitor destructor so that the problematic
>> dynamic cast will succeed.  I am open to any other suggestions as well.  I
>> may have to resort to just creating a small example program that reproduces
>> the issue.
>>
>>
>>
>> Thanks,
>>
>> Rick
>>
>>
>>
>> -Original Message-
>> From: Rick Irons
>> Sent: Wednesday, May 25, 2016 5:56 AM
>&g

Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-27 Thread Robert Osfield
Hi Rick,

As general note, use of a C pointer to scene graph objects include the
CullVisitor should generally be avoided, it's only safe for small
blocks of code where you know that the objects will remain in memory
at all times during the block.  Instead you should use ref_ptr<> to
make sure it's lifetime is correct - if in doubt use ref_ptr<>.

I will have a look at the use of dynamic_cast<> again.  I had to keep
it in there because the pointer to the Referenced base class isn't
castable directly to a CullVsititor as CullVisitor uses virtual
inheritance.

Robert.


On 26 May 2016 at 22:04, Rick Irons <rick.ir...@mathworks.com> wrote:
> Hi Robert,
>
>
>
> Unfortunately the fix didn't address the crash I am encountering.  The issue
> of the dynamic cast in objectDeleted()
> (\openscenegraph\src\osgUtil\CullVisitor.cpp) failing remains...
>
>
>
> virtual void objectDeleted(void* object)
>
> {
>
> osg::Referenced* ref =
> reinterpret_cast<osg::Referenced*>(object);
>
> osgUtil::CullVisitor* cv =
> dynamic_cast<osgUtil::CullVisitor*>(ref);
>
>
>
> OpenThreads::ScopedLock lock(_mutex);
>
>
>
> RenderStageMap::iterator itr = _renderStageMap.find(cv);
>
> if (itr!=_renderStageMap.end())
>
> {
>
> _renderStageMap.erase(itr);
>
> }
>
> }
>
>
>
> I was going to define our object that inherits from the CullVisitor as an
> osg::ref_ptr.  Perhaps doing so will delay the freeing of the CullVisitor
> object long enough within the CullVisitor destructor so that the problematic
> dynamic cast will succeed.  I am open to any other suggestions as well.  I
> may have to resort to just creating a small example program that reproduces
> the issue.
>
>
>
> Thanks,
>
> Rick
>
>
>
> -----Original Message-
> From: Rick Irons
> Sent: Wednesday, May 25, 2016 5:56 AM
> To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org>
> Subject: Re: [osg-users] CullVisitor object not getting properly deleted
>
>
>
> Hi Robert,
>
>
>
> Thanks for the update.   I will try out the fix.
>
>
>
> Rick
>
>
>
>> On May 24, 2016, at 3:53 PM, Robert Osfield <robert.osfi...@gmail.com>
>> wrote:
>
>>
>
>> Hi Rick,
>
>>
>
>> After a preplexing day looking at how the osgUtiil::CullVisitor,
>
>> osg::Camera and RenderStageCache were all interacting via the
>
>> osg::Observer system I finally fixed the problem with the crash that
>
>> I've see with the osgoit and osgprerender examples.   As the crash
>
>> looks similar to what you saw there is reasonable chance that the
>
>> changes should work for you too.
>
>>
>
>> I have checked my fix into master and OpenSceneGraph-3.4.
>
>>
>
>> Robert.
>
>> ___
>
>> 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
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-26 Thread Rick Irons
Hi Robert,



Unfortunately the fix didn't address the crash I am encountering.  The issue of 
the dynamic cast in objectDeleted() 
(\openscenegraph\src\osgUtil\CullVisitor.cpp) failing remains...



virtual void objectDeleted(void* object)

{

osg::Referenced* ref = reinterpret_cast<osg::Referenced*>(object);

osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(ref);



OpenThreads::ScopedLock lock(_mutex);



RenderStageMap::iterator itr = _renderStageMap.find(cv);

if (itr!=_renderStageMap.end())

{

_renderStageMap.erase(itr);

}

}



I was going to define our object that inherits from the CullVisitor as an 
osg::ref_ptr.  Perhaps doing so will delay the freeing of the CullVisitor 
object long enough within the CullVisitor destructor so that the problematic 
dynamic cast will succeed.  I am open to any other suggestions as well.  I may 
have to resort to just creating a small example program that reproduces the 
issue.



Thanks,

Rick



-Original Message-
From: Rick Irons
Sent: Wednesday, May 25, 2016 5:56 AM
To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org>
Subject: Re: [osg-users] CullVisitor object not getting properly deleted



Hi Robert,



Thanks for the update.   I will try out the fix.



Rick



> On May 24, 2016, at 3:53 PM, Robert Osfield 
> <robert.osfi...@gmail.com<mailto:robert.osfi...@gmail.com>> wrote:

>

> Hi Rick,

>

> After a preplexing day looking at how the osgUtiil::CullVisitor,

> osg::Camera and RenderStageCache were all interacting via the

> osg::Observer system I finally fixed the problem with the crash that

> I've see with the osgoit and osgprerender examples.   As the crash

> looks similar to what you saw there is reasonable chance that the

> changes should work for you too.

>

> I have checked my fix into master and OpenSceneGraph-3.4.

>

> Robert.

> ___

> osg-users mailing list

> osg-users@lists.openscenegraph.org<mailto: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


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-25 Thread Rick Irons
Hi Robert,

Thanks for the update.   I will try out the fix.

Rick

> On May 24, 2016, at 3:53 PM, Robert Osfield  wrote:
> 
> Hi Rick,
> 
> After a preplexing day looking at how the osgUtiil::CullVisitor,
> osg::Camera and RenderStageCache were all interacting via the
> osg::Observer system I finally fixed the problem with the crash that
> I've see with the osgoit and osgprerender examples.   As the crash
> looks similar to what you saw there is reasonable chance that the
> changes should work for you too.
> 
> I have checked my fix into master and OpenSceneGraph-3.4.
> 
> Robert.
> ___
> 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


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-24 Thread Robert Osfield
Hi Rick,

After a preplexing day looking at how the osgUtiil::CullVisitor,
osg::Camera and RenderStageCache were all interacting via the
osg::Observer system I finally fixed the problem with the crash that
I've see with the osgoit and osgprerender examples.   As the crash
looks similar to what you saw there is reasonable chance that the
changes should work for you too.

I have checked my fix into master and OpenSceneGraph-3.4.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-24 Thread Rick Irons
Hi Robert,

Thanks for the update.

Rick

From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf 
Of Robert Osfield
Sent: Tuesday, May 24, 2016 5:11 AM
To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org>
Subject: Re: [osg-users] CullVisitor object not getting properly deleted

Hi Rick,

On 23 May 2016 at 20:33, Rick Irons 
<rick.ir...@mathworks.com<mailto:rick.ir...@mathworks.com>> wrote:
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 for pin pointing the change.  The code in question was written to 
address a bug in clean up, so it looks like it's inadvertently introduced it's 
own one.

In testing I've foind the osgoit example crashes in the same manor as you've 
found.  I'm currently looking at resolving this.
Robert.

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-24 Thread Robert Osfield
Hi Rick,

On 23 May 2016 at 20:33, Rick Irons  wrote:

> 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 for pin pointing the change.  The code in question was written to
address a bug in clean up, so it looks like it's inadvertently introduced
it's own one.

In testing I've foind the osgoit example crashes in the same manor as
you've found.  I'm currently looking at resolving this.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-23 Thread Rick Irons
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-boun...@lists.openscenegraph.org] On Behalf 
Of Robert Osfield
Sent: Monday, May 23, 2016 2:02 PM
To: OpenSceneGraph Users <osg-users@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.ir...@mathworks.com<mailto: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 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@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 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<mailto: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


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-23 Thread Robert Osfield
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  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(object);
>
> osgUtil::CullVisitor* cv =
> dynamic_cast(ref);
>
> OpenThreads::ScopedLock 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(object);
>
> osgUtil::CullVisitor* cv =
> dynamic_cast(ref);
>
> OpenThreads::ScopedLock 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(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


Re: [osg-users] CullVisitor object not getting properly deleted

2016-05-23 Thread Julien Valentin
Hi
Your problem is weird, further I don't understand why you would have to create 
yourself a cullvisitor...
Give us the minimum code to reproduce the error please
(and use code section to keep indentation)


Rick Irons 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(object); 
> osgUtil::CullVisitor* cv = dynamic_cast(ref); 
> OpenThreads::ScopedLock 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(object); 
> osgUtil::CullVisitor* cv = dynamic_cast(ref); 
> OpenThreads::ScopedLock 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(itr->first); 
> if (ref==tmpRef) 
> { 
> cv = itr->first; 
> _renderStageMap.erase(cv); 
> break; 
> } 
> } 
> } 
> } 
> 
> Thanks, 
> Rick
> 
>  --
> Post generated by Mail2Forum


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67211#67211





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] CullVisitor object not getting properly deleted

2016-05-23 Thread Rick Irons
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(object);
osgUtil::CullVisitor* cv = dynamic_cast(ref);
OpenThreads::ScopedLock 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@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(object);
osgUtil::CullVisitor* cv = dynamic_cast(ref);
OpenThreads::ScopedLock 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(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