I have my framework powered by AS up and runnig. However if I use casting behaviour with max portability, I get a nice crash.
r = engine->RegisterObjectBehaviour("base", asBEHAVE_REF_CAST, "derived@ f()", asFUNCTION(Wrapper1), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("derived", asBEHAVE_IMPLICIT_REF_CAST, "base@ f()", asFUNCTION(Wrapper2), asCALL_GENERIC); assert( r >= 0 );
where Wrapper1 and Wrapper2 are autowrappers to (refCast<base,derived>) and (refCast<derived,base>).
After this if I do an implicit cast in script, I get a nice crash in system function calling with the object pointer being NULL, debugged it and the object I want to cast is not NULL. With native calling everything is nice and smooth.
Is there a special way I should register casting for max portability?
Version 2.23.0 introduced an improved version of the autowrapper add-on (thanks to SiCrane) that eliminate the need to declare the wrapper and then register it in two separate calls. With the new version you would register it as the following:
r = engine->RegisterObjectBehaviour("base", asBEHAVE_REF_CAST, "derived@ f()", WRAP_OBJ_LAST((refCast<base,derived>)), asCALL_GENERIC); assert( r >= 0 );
#define _DefineFunctionWrapper( m ) struct local { asDECLARE_FUNCTION_WRAPPER( Wrapper, m ); };
Done a little debugging in the meantime.
In the function asWrapNative_p1 the call gen->GetAddressOfReturnLocation() returns NULL. After that it is crashing.
In asCContext::CallGeneric, there is the initialization of gen with: asCGeneric gen(engine, sysFunction, currentObject, args);
That is basically initializing objectRegister to NULL, and later asCGeneric::GetAddressOfReturnLocation returns that.
The changes are the addition of the keyword 'template' in the macros. It is probably what the compiler is expecting. Some compilers manage without the keyword (like MSVC) but it seems the compiler for Android doesn't.
Hopefully this will solve the problem. If it does I'll check in these changes.