1
\$\begingroup\$

I'm trying to figure out the purpose of the '@+' token in Angelscript, near the bottom of the page lists then as auto handles, and if I'm reading it right, then this in action would look like this:

Obj@+ ChooseObj(Obj@+, Obj@+);

void main()
{
    Obj@ A, B;

    {
        @A = new Obj();
        @B = new Obj(); 
    }

    // at this point A and B have a refcount of 1.
    Obj@ C = ChooseObj(A, B);
    //Let C = B, so A got decref'd and was deleted 

    // this should be false, because the object's refcount was deleted,
    // but the pointer wasn't reassigned.
    if(A !is null)
    {
    //this should crash from an invalid pointer
        A.doMethod();
    }
}

Meanwhile, B got decref'd and incref'd, so it has a refcount of 1 when it gets returned, then gets addrefed again when it gets assigned to C. So C/B correctly has a value of 2, but that seems to be more a coincidence than anything.

In short I feel like I must be reading this wrong. What is it talking about?

\$\endgroup\$
1
  • \$\begingroup\$ Are you sure about that behaviour? From reading the documentation, it appears that A's refcount is incremented when it's passed to ChooseObj and using auto-handles means that ChooseObj automatically dereferences that before returning, so A goes back to what it was before the function call. \$\endgroup\$
    – Pharap
    Commented May 13, 2017 at 16:02

0

You must log in to answer this question.

Browse other questions tagged .