Jump to content
  • Advertisement
Sign in to follow this  
justin12343

Can't seem to copy return value?

This topic is 887 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
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. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!