Skip to main content
GameDev.net gamedev.net
🔒 Locked

Autohandles with generic callconv

Started by chewbakka Aug 29, 2012 at 10:57 AM 1 replies 1.5k views
Original Post
chewbakka
chewbakka
Since I use AS there is a bug in the generic calling convention when returning auto handles.

When a function returns an autohandle, the generic callconv doesn't increase it's reference counter and later it is going to cause crashes. I've managed to fix this by adding

[source lang="cpp"] if ( sysFunction->returnType.IsObject()
&& !sysFunction->returnType.IsReference()
&& sysFunction->returnType.IsObjectHandle()
&& sysFunc->returnAutoHandle
&& m_regs.objectRegister )
m_engine->CallObjectMethod( m_regs.objectRegister, sysFunction->returnType.GetObjectType()->beh.addref );
[/source]

to the asCContext::CallGeneric function before "Clean up function parameters" (line 4382 in 2.24.1).

I'm using this for a long time now (copying it over upon AS upgrade), but not sure if this is the correct solution. It works though.
WitchLord
WitchLord
Auto handles were only intended to be used with native calling conventions. For generic calling conventions they have always been ignored.

However, I'll look into this scenario to see if a definite solution can be made.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
chewbakka
chewbakka
I use autohandles on my script interface. The solution itself can be compiled to use native calling conventions or generic, based on the target device (I use generic on android mips and used to use it for arm too before). I use macros like

_DelegateClassMethod( T, FrameServer, AddListener );

and the compiler decides if it is going to be registered natively or generic. With the little fix, the autohandles are working well for generic calling too (no crashes/leaks).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.