Angelscript copy constructor crash

Started by
0 comments, last by WitchLord 11 years, 2 months ago

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

Advertisement

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

This topic is closed to new replies.

Advertisement