Advertisement

array with object reference

Started by February 10, 2014 06:13 AM
5 comments, last by loboWu 10 years, 9 months ago

[source][/source]Dear Andreas:
I found there's something strange about array constructor in 2.18.1.

I had a string class which is registered with reference.
The codes are similar with http://www.gamedev.net/topic/639252-asobj-ref-and-asobj-value-at-the-same-time/

and here is my testing code without fail
[source]import void SetCurrentModel(string) from "model2";
void test(uint idx)
{
string@[] models={"111", "222", "333", "444", "555", "666", "666"};
if (idx <=6) SetCurrentModel(models[idx]);
else
SetCurrentModel("");
}[/source]


If I change the string array codes like this

[source]import void SetCurrentModel(string) from "model2";
void test(uint idx)
{
string[] models={"111", "222", "333", "444", "555", "666", "666"}; //replace "string@ " with "string"
if (idx <=6) SetCurrentModel(models[idx]);
else
SetCurrentModel("");
}[/source]

There are some string memory leak in 2.18.1. (but that's fine in 2.17.0)

I couldn't point out the bug exactly, but I think there are 2 bugs with object reference array

1. value assignment operators on reference types

2. CScriptArray::Construct()

Thanks. I'll look into this.

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

I'm not able to reproduce any problem. The following tests work correctly without any memory leaks.

// Test initializing an array with string registered as reference type
// http://www.gamedev.net/topic/653233-array-with-object-reference/
{
  engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
  engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
  RegisterScriptString(engine); // ref type
  RegisterScriptArray(engine, true);
  engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
 
  r = ExecuteString(engine, "string@[] a = {'a', , 'c', , 'e'}; assert( a[1] is null ); assert( a[2] == 'c' );");
  if( r != asEXECUTION_FINISHED )
    TEST_FAILED;
 
  r = ExecuteString(engine, "string[] a = {'a', , 'c', , 'e'}; assert( a[1] == '' ); assert( a[2] == 'c' );");
  if( r != asEXECUTION_FINISHED )
    TEST_FAILED;
 
  engine->Release();
}

Make sure you have updated the CScriptArray add-on with the latest version from the SDK.

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

Dear Andreas:

I could reproduce the bug.

But it occurs only when loading bytecode and run.

I think there are 2 bug

1. string[] ar = {"a", "b", "c", "d", "e", "f", "g"} has memory leak,

in my env, the memory leak maybe "e" , "f", "g" .....

2. when calling SetCurrentModel(ar[2]), it will raise an exception

at string opAssign() with an illegal parameter.

Thanks a lot.

OK. I didn't test with loading pre-compiled bytecode. I'll check that tonight.

It sounds like the bug is in the as_restore.cpp then.

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

That was it.

I've fixed the problem in revision 1833.

Thanks,

Andreas

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

Thanks a lot.biggrin.png

This topic is closed to new replies.

Advertisement