I'm still quite new to Angelscript and I have some trouble understanding what's going here.
I'm trying to pass a global variable in my script to a function that accept a const & parameter. Things seems to work as expected when I use a primitive or a class declared in the same script, but as soon as I'm trying to do this with a type I registered from the application I run directly into a failed assertion:
Assertion failed: (useVariable), function PerformFunctionCall, file [...]/angelscript/source/as_compiler.cpp, line 12833.
if( descr->returnType.IsObject() && !descr->returnType.IsReference() ){
int returnOffset = 0;
if( descr->DoesReturnOnStack() ){
asASSERT( useVariable );
// The variable was allocated before the function was called
returnOffset = varOffset;
ctx->type.SetVariable(descr->returnType, returnOffset, true);
// The variable was initialized by the function, so we need to mark it as initialized here
ctx->bc.ObjInfo(varOffset, asOBJ_INIT);
}
It really seems to be related to the fact that the variable I'm trying to pass as a parameter is global and from a custom type. I tried doing the same inside a class and I don't have any problem. As explained above I don't have this issue with primitives or types created in the script, so my first guess would be that I'm doing something wrong with the registration. Which is probably the case as this is the first class I'm trying to register to AS.
I'm registering my type as asOBJ_VALUE and asOBJ_APP_CLASS_CDAK.
Here's an example code to illustrate what I'm doing.
float test1;
Vec2f test2; // Vec2f is the registered type
void main(){ // main is the function called
testFloat( test1 ); // works
testVec2f( test2 ); // crash with "Assertion Failed"
}
void testFloat( const int ¶m ){}
void testVec2f( const Vec2f &in param ){}
// the two following work without surprise but I would really prefer
// keeping the const correctness of the class I register to AS
void stupidTestVec2f( const Vec2f param ){}
void stupidTest2Vec2f( Vec2f param ){}
I guess it is somehow related to the way I register my Vec2f type, but I can't seem to find the correct way and I've tried to find solution here without success.
As a side question, is "const T &in" the closest to what "const T &" means in c++?
Thanks!
Simon.