• Advertisement
Sign in to follow this  

Angelscript copy constructor crash

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



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,

Share this post

Link to post
Share on other sites

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/




Share this post

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

  • Advertisement