Jump to content
  • Advertisement
Sign in to follow this  
AgentC

Accessing non-primitive properties of a reference type

This topic is 2781 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

Hi,
I had some trouble exposing read/write access to properties of a reference type, when they were registered with RegisterObjectProperty().

The reference type in question was a skeletal animation bone object, which had Vector3, Quaternion and bool properties:
Vector3 initialPosition
Quaternion initialRotation
Vector3 initialScale
bool enabled

Vector3 & Quaternion themselves are registered as POD value types. Whenever I tried to change the Vector3 & Quaternion properties of the bone (pointed to by an object handle), I would get the compilation error "Reference is temporary". Changing the bool property would work fine.

I worked around this by registering set_ and get_ accessors for the Vector3's & Quaternion, instead of using RegisterObjectProperty(). But I'd like to understand why this is necessary.

Share this post


Link to post
Share on other sites
Advertisement
There's actually a chain of object handles / handle properties ... I'll post the relevant registration and script code:

Bone:
engine->RegisterObjectType("Bone", 0, asOBJ_REF);
...
engine->RegisterObjectProperty("Bone", "Vector3 initialPosition", offsetof(Bone, initialPosition_));
engine->RegisterObjectProperty("Bone", "Quaternion initialRotation", offsetof(Bone, initialRotation_));
engine->RegisterObjectProperty("Bone", "Vector3 initialScale", offsetof(Bone, initialScale_));
engine->RegisterObjectProperty("Bone", "bool enabled", offsetof(Bone, enabled_));

Skeleton:
engine->RegisterObjectType("Skeleton", 0, asOBJ_REF);
...
engine->RegisterObjectMethod("Skeleton", "Bone@+ get_bones(uint) const", asMETHODPR(Skeleton, GetBone, (unsigned), Bone*), asCALL_THISCALL);

AnimatedModel:
engine->RegisterObjectType("AnimatedModel", 0, asOBJ_REF);
...
engine->RegisterObjectMethod("AnimatedModel", "Skeleton@+ get_skeleton() const", asMETHOD(AnimatedModel, GetSkeleton), asCALL_THISCALL);


Script code that would produce the error: (assume an AnimatedModel that has been initialized so that it has the skeleton & bones objects)

AnimatedModel@ model = node.GetComponent("AnimatedModel"); // this should not be relevant, we just get the object handle to AnimatedModel
model.skeleton.bones[0].initialPosition = Vector3(1.0f,1.0f,1.0f); // this fails with "Reference is temporary"

Share this post


Link to post
Share on other sites
This was a bug. I had a check in the code to disallow reassigning handles in temporary variables. As your get property accessors are returning handles, these are stored in temporary variables. While you're not actually reassigning the temporary handle, the check for that was still triggered.


I've fixed this bug in revision 855.


Thanks

Share this post


Link to post
Share on other sites
Thanks! I noticed there are also default values for function parameters implemented in SVN, very nice :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!