I have registered a function that returns a handle to an array. This array contains handles to reference types.
In my script, if i write:
Node@ subnode;subnode = @input.GetSubnodes()[0];
it seems that further operations on the "subnode" handle gets the wrong pointer.
Now, I can express the same thing differently, in which case it works as expected.
Node@[]@ nodearray = @input.GetSubnodes();Node@ subnode;subnode = @nodearray[0];
Here is the registration and script
// --- Type registration on C++ side ---void RegisterType(asIScriptEngine* engine){ int r = engine->RegisterObjectType("Node",0,asOBJ_REF); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Node", asBEHAVE_FACTORY,"Node@ f()", asFUNCTION(Node_Constructor), asCALL_CDECL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Node", asBEHAVE_ADDREF, "void f()", asMETHOD(Node,AddRef), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Node", asBEHAVE_RELEASE, "void f()", asMETHOD(Node,Release), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod("Node","Node@[]@ GetSubnodes()",asFUNCTION(Node_GetSubnodes),asCALL_GENERIC);assert( r >= 0 ); r = engine->RegisterObjectMethod("Node","int get_member()",asFUNCTION(Node_GetMember),asCALL_CDECL_OBJLAST);assert( r >= 0 ); r = engine->RegisterObjectMethod("Node","void set_member(int)",asFUNCTION(Node_SetMember),asCALL_CDECL_OBJLAST);assert( r >= 0 );}//// --- Script ---void TestFunc(Node@ input){ Node@[]@ nodearray; Node@ subnode; // Case 1. Works as expected @nodearray = @input.GetSubnodes(); @subnode = @nodearray[0]; int value1 = subnode.member; // <- ok // Case 2. Wrong address sent to following operations on "subnode" @subnode = @input.GetSubnodes()[0]; int value2 = subnode.member; // <- weird behavior}