Skip to main content
GameDev.net gamedev.net
🔒 Locked

Can't seem to copy return value?

Started by justin12343 Jan 18, 2016 at 3:54 PM 0 replies 1.8k views
Original Post
justin12343
justin12343

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
}
WitchLord
WitchLord

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() 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 - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.