• Advertisement
Sign in to follow this  

array with object reference

This topic is 1442 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[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()

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement