Hi Preet, On 17/03/12 8:09 , Preet wrote: > If I do this, then I need to maintain the underlying ref_ptr object > no? This isn't particularly convenient. What was wrong with assigning > the osg::Node's pointer to mysteryPtr instead? Basically with ... > > osg::ref_ptr<osg::Node> someNode; > mysteryPtr = someNode.Get(); > > As long as the pointer returned by the Get() method is valid for the > lifetime of the object I'm safe right? Then if I want to do anything > with object: > > osg::ref_ptr<osg::Node> someNode = some_cast_call<osg::Node*>(mysteryPtr); > someNode->partyAllDay();
That's not going to work terribly well, the Get() method simply cannot make guarantees that the pointer is valid. You *MUST* keep a osg::ref_ptr around to keep the object alive, otherwise you'll end up with a stale pointer to a deleted object at some point. So you might as well do that inside your struct. Without knowing your plans in detail I'd think about using a virtual base class as an interface (call it IMysteryStruct) that has a public method to return a void* if you need it (although I don't see a use for that). This is the class that you'd pass around internally. Then you can make derived classes, such as OsgMysteryStruct (which has an internal osg::ref_ptr to the object in question) or a SharedMysteryStruct (which has an internal shared_ptr to some object). Cheers, /ulrich _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

