Sign in to follow this  

Can't seem to copy return value?

This topic is 729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
}

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

This topic is 729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this