Yes. The semantics of observer_ptr guarantee the existence of the target
object ONLY after calling lock(). Only by calling lock() can you know for
point to an existing object. Avoid observer_ptr::get() and always use the
lock() idiom.
lock() populates a true ref_ptr with the object pointer. If there were no
undesirable behavior. So returning false makes sense.
Post by Kristofer KrusHi Robert,
Thanks. I'm having the problem that an observer_ptr that is assigned a
pointer to an object that hasn't yet been assigned to a ref_ptr looks like
it is invalid when I try to lock it (but not when I call the get method, so
there is a discrepancy between observer_ptr::lock and observer_ptr::get in
that sense). When the pointer is also assigned to a ref_ptr so that the
reference count in the referenced object goes up, the lock method starts to
return true instead of false.
Here is what I do: In the constructor of a class that is referencable, I
create an observer_ptr, obs, that is assigned the this-pointerâpointing at
object A, which is the object being constructedâand I send obs to another
object B that wants to observe A. at this point, it looks like obs is
invalid. Directly after A has been constructedâby using the new-keywordâits
memory address is assigned to a ref_ptr and obs.lock suddenly starts to
succeed.
Is this desirable behavior? I mean, the object exists, right? Why would
otherwise get() succeed? Also, if you create an obs_ptr to an object
located on the heap, that won't work as expected either when you try to
lock it.
Cheers,
Kristofer
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75114#75114
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org