Keith Parkins wrote on Wednesday, April 25, 2007 2:44 PM:
> Oops, I take it back. That didn't solve the problem.
>
> I can tell you that the access violation occurs on a pointer to an
> object named Screen which seems to be in Producer.
Ah well, it's still an improvement IMHO ;)
You aren't creating any ref_ptr loops, are you (i.e. A has a ref_ptr to
B, which has a ref_ptr to A)?
If that isn't it, either, then can you produce a simple test case; I'm
still not 100% clear on what you're wanting to do with this code.
> On Wed, 25 Apr 2007, Keith Parkins wrote:
>
>> That did it.
>>
>> Thanks,
>> -K
>>
>> On Wed, 25 Apr 2007, Thrall, Bryan wrote:
>>
>>> Keith Parkins wrote on Wednesday, April 25, 2007 1:45 PM:
>>>> I am a bit fuzzy on reference pointers and am not certain why the
>>>> following is bad although I have a gut feeling as to why.
>>>>
>>>> I have a class Derived which is derived from base class MY_D_REF
>>>> which is a descendant of osg::Referenced. Derived is also a direct
>>>> decedent of osgGA::GUIEventHandler.
>>>>
>>>> class Derived : public MY_D_REF, public osgGA::GUIEventHandler,
>>>> class MY_D_REF : public osg::Referenced
>>>
>>> osgGA::GUIEventHandler also is derived from osg::Referenced, so
>>> you're actually inheriting from that class multiple times. Try
>>> using virtual inheritance.
>>>
>>>>
>>>> Class MY_D_REF has a callback which uses a this * to pack its
>>>> callback data:
>>>>
>>>> trans->setUserData(this);
>>>> trans->setUpdateCallback(new MyCallback);
>>>>
>>>> //---------------------------------------------------------------
>>>> class MyCallback : public osg::NodeCallback {
>>>> public:
>>>> virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
>>>> { osg::ref_ptr<MY_D_REF> wp = dynamic_cast<MY_D_REF*>
>>>> (node->getUserData()); /--- do stuff --/
>>>> traverse(node, nv);
>>>> }
>>>> When Derived is destroyed at the end of the program, I get an
>>>> access violation (xmemory's (windoze) destructor template).
>>>>
>>>> IF Derived is not derived from both classes, everything is okay.
>>>>
>>>> or
>>>>
>>>> IF I take out the callback, everything is okay.
>>>>
>>>> When I say that everything is okay, I mean the program exits
>>>> fine. I understand that everything is not in fact okay.
>>>>
>>>> Is this because of packing my callback with a this pointer and
>>>> it's not getting its count decreased? Is that bad mojo? Is there
>>>> something special I should be doing to decrease the reference the
>>>> MY_D_REF object in its destructor? I have the destructors
>>>> protected for the derived classes. Or is this a something that I
>>>> might run into because multiple ancestors are derived from
>>>> osg::Referenced? I was worried about a possible circular
>>>> reference, so I took out reference pointers in the derived
>>>> classes, but the results were the same.
>>>>
>>>> Thanks,
>>>> Keith
>>>
>>> HTH,
--
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/