[sldev] Why won't isAvatar() work?

Michael Miller 1337mail at gmail.com
Thu Oct 4 04:21:57 PDT 2007


Dale,
That idea seems good, but a hack nonetheless(since it needs to be made at
object creation). I want to modify the core SL code as little as possible. I
remember in 1.18.1.2, the isAvatar() method worked at the end of the
processObjectUpdate method. Has anything (significant) changed in this
method since then? Are there no such smart pointers already in the code in
the processObjectUpdate method? I'd rather (if at all possible) avoid using
any code except at the end of the method after all the "original" SL code
has been executed.

-- MIke


On 10/4/07, Dale Glass <dale at daleglass.net> wrote:
>
> On Thu, Oct 04, 2007 at 12:12:56AM -0400, Michael Miller wrote:
> > Jason,My apologies, but I am unable to understand fully what you mean. I
> > understand that a pointer may be pointing to nothing(but even
> if(&objectp &&
> > objectp->isAvatar()) doesn't work). How would I make use of an
> LLPointer?
> > Would this really help?
>
> The problem with manual memory management is that there can be confusion
> regarding what is freed when.
>
> For example, the viewer internally keeps tracks of objects which get
> constantly created and destroyed. It's possible to get a pointer to an
> object which isn't there anymore because it's been free'd. At that
> point you have a pointer pointing to something that used to be a
> object, but no longer is. Its memory may have well been overwritten
> by something completely unrelated.
>
> To prevent that, you can use a smart pointer, which automatically
> deletes an object when nothing is pointing at it anymore. This both
> prevents leaking memory (not in all cases) and freeing it prematurely.
>
> You declare it as LLPointer<LLViewerObject> ptr = new LLViewerObject();
>
> then you can copy ptr around, and when all copies disappear, the object
> will be freed.
>
> Note that for this to work the LLPointer needs to be created during the
> object's creation and be the one way to get a pointer to it. You can't
> just create a LLPointer from some normal pointer passed to you and have
> that work right.
>
> By that I mean that if you write a function like:
>
> void doStuff( LLViewerObject *vo )
> {
>        LLPointer<LLViewerObject> ptr = vo;
>        if ( ptr->isAvatar() )
>        {
>                llinfos << "is an avatar" << llendl;
>        }
> }
>
> Then that'll result in the object getting freed when the function
> returns, and that would be a very bad thing.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.secondlife.com/pipermail/sldev/attachments/20071004/456e41f3/attachment-0001.htm


More information about the SLDev mailing list