Jump to content
  • Advertisement
Sign in to follow this  

Two questions about arrays

This topic is 2572 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

1) Is there any way, to register native C++ static arrays?
[s]2) I followed steps from this example code: http://www.angelcode...ddon_array.html to register CScriptArray containing Block_Vector's (it's my custom class). How should I register that kind of array as a global property? I did it this way: [/s]

CScriptArray* resultsV;
RegisterScriptArray(ASM->GetEngine()->m_ptr, true);

asIObjectType* t = ASM->GetEngine()->m_ptr->GetObjectTypeById(ASM->GetEngine()->m_ptr->GetTypeIdByDecl("array<Vector>"));
resultsV = new CScriptArray(1000000, t);
for( int i = 0; i < 1000000; i++ )
Block_Vector** p = static_cast<Block_Vector**>(resultsV->At(i));
*p = new Block_Vector(0.0f, 0.0f, 0.0f, 0.0f);

ASM->GetEngine()->m_ptr->RegisterGlobalProperty("array<Vector> g_resultsV", &resultsV);

When I use g_resultsV in script in loop, this statement causes crash: g_resultsV[ no ].
It looks like my CScriptArray is totally wrong and uninitialized, it's buffer is NULL.
What should I fix in my code?

I'm using the latest 2.20.3 version of Angel Script.

Ad 2) It was stupid mistake, it was here:
ASM->GetEngine()->m_ptr->RegisterGlobalProperty("array<Vector> g_resultsV", &resultsV);
I passed pointer to pointer, working version looks like this:
ASM->GetEngine()->m_ptr->RegisterGlobalProperty("array<Vector> g_resultsV", resultsV);

It still crashes :/.

Again... it was my mistake :).
Working code:
Block_Vector* p = static_cast<Block_Vector*>(resultsV->At(i);
p = new Block_Vector(0.0f, 0.0f, 0.0f, 0.0f);

But my question number 1 is still open :).

Share this post

Link to post
Share on other sites
The only way to directly register a static array, is as if it was a fixed size structure, for example a float[3] can be registered with RegisterObjectType("float3", sizeof(float[3]), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS);. Of course this only works if the array is always the same size.

If the array is a member of a class, it is probably easiest to use property accessors to expose the array itself rather than trying to register a type to represent the array.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!