Advertisement

Array bug?

Started by June 27, 2010 02:53 AM
2 comments, last by Lars Peter 14 years, 5 months ago
Hi. I found some wierd behavior:

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}
I'll look into this immediately. Thanks for the clear report.

[edit] Yes. It is indeed a bug. I've been able to reproduce it. I should have the solution within a couple of hours.

[Edited by - WitchLord on June 27, 2010 9:56:49 AM]

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Fixed in SVN revision 607.

The problem happened not because of the array itself, but because you had a situation where a method on a temporary handle returned a reference to a handle.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Wow, that was a fast response and fix. Thanks a lot ;)

I have downloaded the fix and confirmed that it is working.

Thanks again for a great library and awesome support!

This topic is closed to new replies.

Advertisement