Hi,
Working to implement AngelScript into my game project, but I'm having issues with the assign operator - using it results in a debug assertion error with "Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
I'm trying to use GLM with my scripts, so I've made a VEC2_REF struct to interface between GLM and AngelScript, that holds the required addref and release functions. This is also where I have the operator = overload - basicly it just calls GLM's own operator overload.
struct VEC2_REF : public REF_COUNTER // REF-COUNTER contains addref and release functions
{
VEC2_REF( vec2 v )
: v( v )
{}
vec2 v;
VEC2_REF &operator=( VEC2_REF &r)
{
if( this != &r )
v = r.v; // Call GLM's operator overload
return *this;
}
};
This is how I'm registering the object to angelscript
engine->RegisterObjectType( "vec2", sizeof(VEC2_REF), asOBJ_REF );
...
/* Various behavior functions - not important for this */
/* Various operator overloads being registered... */
engine->RegisterObjectMethod( "vec2", "vec2 @opAssign(vec2&)", asMETHODPR( VEC2_REF, operator=, (VEC2_REF&), VEC2_REF& ), asCALL_THISCALL );
/* Various extra functions... */
...
// Vec2 properties NB: offset with sizeof(int) to skip over the nRefs variable in REF_COUNTER class
engine->RegisterObjectProperty( "vec2", "float x", sizeof(int) + sizeof(float) * 0 );
engine->RegisterObjectProperty( "vec2", "float y", sizeof(int) + sizeof(float) * 1 );
And this is the script itself
void main()
{
vec2 a;
a.x = 2.0f;
a.y = 5.0f;
vec2 b( 7, 10 );
log( a );
log( b );
a = b;
log( a );
}
The weird is that it doesn't actually crash on a = b; However it only the error only occurs IF the assign is there.
Also the last log call will output something weird if the assign operator have been used.
v( 2 5 )
v( 7 10 )
v( -1.59e+038 -1.59e+038 )
I really can't figure out what I'm doing wrong, or why this is happening; all other operators are fine. Any help would be highly appreciated.
mSkull