Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Feb 2014
Offline Last Active Jul 04 2014 02:15 PM

Topics I've Started

Global variables and const argument by reference.

27 February 2014 - 04:19 PM

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 &param ){}
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++?




Crash in CallCDeclFunction*/asm __volatile__ on MacOS 32-bit and not in 64-bit

16 February 2014 - 05:34 AM



First of all thank you for this great library! I discovered it a few days ago, and I don't think I'll be able to look back!


I'm having a few issues trying to make it work in 32-bit (i386) with XCode 5 and OSX 10.9. Everything works great in 64-bit and it doesn't seem to change anything to build the library in 32 or 64 bit, a crash always happen in the same file if I try to run the application in 32-bit.


I've found a post on the forum from a few years ago that seams to be related to my problem as everything seems to happen in that same CallCDeclFunctionObjLast, but what I found in the post didn't helped and that bug seems to have been corrected since a few release anyway (that was in 2012!).


If it's relevant, I think that the function the engine is trying to execute is the constructor of an object I registered that way:

   template<typename T, typename P1, typename P2>
       static void constructor(P1 p1, P2 p2, T* ptr) { new (ptr) T(p1,p2); }
r = engine->RegisterObjectBehaviour(name.c_str(),
                                    ( "void f("+type+","+type+")" ).c_str(),
                                    asCALL_CDECL_OBJLAST); assert( r >= 0 );

Actually if I build the library without any debug symbols the only message I got is "error: memory read failed for 0xd04fae00" so that might have something to do with how I handle constructors (which seem to be the way to do it according to the wiki)


So basically I'm a bit lost and wanted to know if that's a known issue, if anyone experienced the same with XCode5/llvm/32bit or if I'm just doing something wrong in my script/binding code.


Any suggestions are welcome!


Thanks a lot!