Jump to content
  • Advertisement
Sign in to follow this  
andrew1b

Trouble with &inout

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

I'm trying to bind a global function that has a pointer to an &inout object handle as parameter. That's my object:
r = pASEngine->RegisterObjectType("Entity", 0, asOBJ_REF); assert(r >= 0);
r = pASEngine->RegisterObjectBehaviour("Entity", asBEHAVE_ADDREF, "void f()", asFUNCTION(DummyAddRef),  asCALL_CDECL_OBJLAST); assert(r >= 0);
r = pASEngine->RegisterObjectBehaviour("Entity", asBEHAVE_RELEASE, "void f()", asFUNCTION(DummyRelease),  asCALL_CDECL_OBJLAST); assert(r >= 0);

That's the global function:
r = m_pASEngine->RegisterGlobalFunction("bool DeleteEntity(Entity@ &inout)", asFUNCTION(DeleteEntity), asCALL_CDECL); assert(r >= 0);

I receive the following error message:
Only object types that support object handles can use &inout. Use &in or &out instead.
This one works fine:
r = m_pASEngine->RegisterGlobalFunction("bool Collide(const Entity &in, Entity@ &out)", asFUNCTION(CollideStatic), asCALL_CDECL); assert(r >= 0);

My reference object has been working with and @&out very fine so far. Why is that? I suppose AngelScript doesn't support @&in, I am right? I googled the documentation and I haven't found anything about that.

Share this post


Link to post
Share on other sites
Advertisement
Entity &inout is allowed but not Entity@ &inout

This is because the Entity object is reference counted but not the handle to Entity object.

How did you plan on implementing the DeleteEntity function? I hope you weren't planning on calling delete on the received object directly. That would be highly risky as there's no telling what other references to the object that are still hanging around.

Share this post


Link to post
Share on other sites
The reason why I wanted to use an @&inout is that after deleting the object that it pointed to I would set its pointer to null, making it safer.
But that's ok, I'll implement a shared pointer using a proxy object. I should have done that from the beginning... now that the Entity object has lot's of methods it's going to be much harder.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!