Jump to content
  • Advertisement
Sign in to follow this  
sepul

Refs without AddRef/Release

This topic is 2606 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 :



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 );


Share this post


Link to post
Share on other sites
Advertisement
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:


void _NullFunc(Physics *ptr)
{
}

If you have a lot of classes to register without proper reference counting, you can template the _NullFunc:


template <class T> void _NullFunc(T* ptr)
{
}

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:


void _NullFunc(Physics *ptr)
{
}

If you have a lot of classes to register without proper reference counting, you can template the _NullFunc:


template <class T> void _NullFunc(T* ptr)
{
}



thanks for the hint

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!