Sign in to follow this  

Refs without AddRef/Release

This topic is 2394 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 know I can't create objects without AddRef, Release behaviors, but how can I register Ref objects without implementing AddRef/Release (for example setting _Void function) for them ?
for example singletons or references to existing application objects ?
I just don't want to override all of my classes with AddRef/Release, that's a little bit lame.

I did something like this, and I got assertion failure at registering asBEHAVE_ADDREF behaviour :


[code]
r = asEngine->RegisterObjectType( "physics", 0, asOBJ_REF ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectBehaviour( "physics", asBEHAVE_FACTORY, "physics@ f()", asFUNCTION(phys::Physics::Instance()), asCALL_CDECL ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectBehaviour( "physics", asBEHAVE_ADDREF, "void f()", asFUNCTION(_NullFunc), asCALL_CDECL ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectBehaviour( "physics", asBEHAVE_RELEASE, "void f()", asFUNCTION(_NullFunc), asCALL_CDECL ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectMethod( "physics", "void foo()", asMETHOD(phys::Physics, Foo), asCALL_THISCALL );
[/code]

Share this post


Link to post
Share on other sites
It fails because asCALL_CDECL is an illegal calling convention in this case, as AngelScript must be able to pass the object pointer to the function. You need a function that takes the object pointer as a parameter, and then you can use for example asCALL_CDECL_OBJLAST convention:

[code]
void _NullFunc(Physics *ptr)
{
}
[/code]
If you have a lot of classes to register without proper reference counting, you can template the _NullFunc:

[code]
template <class T> void _NullFunc(T* ptr)
{
}
[/code]

Share this post


Link to post
Share on other sites
[quote name='AgentC' timestamp='1306597685' post='4816799']
It fails because asCALL_CDECL is an illegal calling convention in this case, as AngelScript must be able to pass the object pointer to the function. You need a function that takes the object pointer as a parameter, and then you can use for example asCALL_CDECL_OBJLAST convention:

[code]
void _NullFunc(Physics *ptr)
{
}
[/code]
If you have a lot of classes to register without proper reference counting, you can template the _NullFunc:

[code]
template <class T> void _NullFunc(T* ptr)
{
}
[/code]
[/quote]

thanks for the hint

Share this post


Link to post
Share on other sites

This topic is 2394 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this