Can't seem to copy return value?

Started by
0 comments, last by WitchLord 8 years, 3 months ago

Angelscript does not seem to be able to properly call the copy constructor of a simple POD type that is being returned from a registered global function for some reason. When it does call the copy constructor, the this pointer of the new object is null, but the input variable has a valid address from the c++ function. I'm using version 2.31.0 WIP.

The problem seems to be around line 1097 in as_callfunc_x86.cpp:


// Copy return value from EAX:EDX
lea  ecx, retQW
mov  [ecx], eax
mov  4[ecx], edx

My C++ code:


PointF Instance::GetBodyPos()
{
	PointF pos;

	if (pBody)
	{
		pos.Set( pBody->GetPosition().x*MTP_RATIO, pBody->GetPosition().y*MTP_RATIO);
	}
	
	return pos; //<------------- Crashes on return. pos gets passed in correctly though
}
Advertisement

Most likely the cause is that you've not registered the PointF type correctly with AngelScript. This causes AngelScript to think that C++ will return it in one way, but in reality C++ will return it in a completely different way. My guess is that AngelScript thinks type will be returned in the CPU registers EAX:EDX, but C++ is most likely returning it in memory.

Please show me how you registered PointF in the call RegisterObjectType and the C++ class declaration so that I can check if you used the correct flags.

Unless you already are doing so, use of the asGetTypeTraits<PointF>() function is recommended as it reduces the risk of picking the wrong flags.

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