Jump to content
  • Advertisement
Sign in to follow this  
andrew1b

Release (ref counted) called twice

This topic is 3136 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'm having trouble with my reference counted object in AngelScript: Script code:
//Decl: Entity @SeekEntity(const string &in)
Entity @circle = SeekEntity("red_circle");
The problem is that the release method is being called twice, while the addref is called once. It turns the reference counter to zero and deletes it. I have followed it with the debugger and I saw that both release calls come from AS. The reference counter is starting from 1 (in the constructor). If remove the code line above the program runs OK. Why is it happening?

Share this post


Link to post
Share on other sites
Advertisement
Since SeekEntity is returning a handle it must increment the reference counter for that object. Alternatively you can use autohandles when registering the function, i.e.:


engine->RegisterGlobalFunction("Entity @+ SeekEntity(const string &in)", asFUNCTION(SeekEntity), asCALL_CDECL);




Share this post


Link to post
Share on other sites
Thank you again Andreas, it worked.
One suggestion: the "Registering a reference type" section of the manual could talk about it or at least link the the page where the "+" modifier is presented (if there is one). I think it would avoid this kind of post.

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!