Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Angelscript copy constructor crash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 assainator   Members   -  Reputation: 681

Like
0Likes
Like

Posted 06 February 2013 - 10:03 AM

Hello,

 

I'm learning how to bind C++ classes to Angelscript, but I've run into a problem, when adding a copy constructor to a class, the application crashes. I'm pretty sure that I'm doing something wrong because I can't seem to find an example on how to do this properly.

 

The class I'm registering is a simple 3D vector with 3 floats (x,y,z).

 

The class registration:

int r = engine->RegisterObjectType("vec3f", sizeof(vec3f), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);

 

copy constructor registration:

r = engine->RegisterObjectBehaviour("vec3f", asBEHAVE_CONSTRUCT, "void f(const vec3f &in)", asFUNCTION(vec3fCopyConstructor), asCALL_CDECL_OBJLAST);

 

the function 'vec3fCopyConstructor':

void vec3fCopyConstructor(void *memory, const vec3f& other)
{
	new(memory) vec3f(other);
}

 

Thanks a lot in advance for any help,


"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3366

Like
0Likes
Like

Posted 06 February 2013 - 12:45 PM

Hi assainator,

 

The problem is because you inverted the order of the arguments to the vec3fCopyConstructor. You registered it with asCALL_CDECL_OBJLAST, but the object pointer (in your case memory) is the first argument. 

 

Either change the order of the arguments, or change the calling convention to asCALL_CDECL_OBJFIRST. :)

 

If you want an example to follow I suggest you take a look at the script math complex add-on that you'll find in the folder sdk/add_on/scriptmath/

 

Regards,

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS