Advertisement

Add support for ref-counted system which uses 0 as initial ref count?

Started by September 08, 2015 09:51 AM
4 comments, last by glcolor 9 years, 2 months ago
Hi,Andreas.
Recently I have to add scripting support for an old project,this project uses a ref-counted system which uses 0 as the initial ref count instead of 1,just like COM, this causes crash in AngelScript by the wrong ref count, could you add some support for this kind of ref-counted system?
Thanks a lot.

As far as i know, the only place where Angelscript needs to know the ref count is when using the asBEHAVE_GETREFCOUNT behavior. Simply adding 1 when returning this value should suffice, unless i'm missing something.

Advertisement
I have not noticed asBEHAVE_GETREFCOUNT before,it looks like just be used by classes registered with asOBJ_GC,but I registered the classes with only the asOBJ_REF flag,so only asBEHAVE_ADDREF and asBEHAVE_RELEASE will be used. I'll study it,thanks.

Solokiller is correct. Besides asBEHAVE_GETREFCOUNT AngelScript doesn't need to know the actual value of the refcount.

The only thing the application must make sure is that when it returns a handle to the script the refcount for the returned handle is accounted for, as AngelScript will release that handle afterwards when it is done with it. This can either be done manually or automatically using the auto-handles @+.

Whether your refcount starts at 0 or 1 has no importance to AngelScript, as long as you implement the release behavior accordingly, i.e. if it starts at 0, you'll want to destroy the object when the refcount becomes negative rather than when it reaches 0.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'll take a further study on it,thanks a lot.
At last I solved the problem by using the autohandles, it's all ok now.

This topic is closed to new replies.

Advertisement