Jump to content
  • Advertisement
Sign in to follow this  
zopenge

I found an reference bug in angelscript.

This topic is 3786 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

class A { A& do( ); }; A& A::do( ) { ... do something. .. } AS Code : { A a; a.do( ); } I use asOBJ_REF to count the object used number. Release() will call 2 times. ( 1 time is correct, My refcount is 1 )

Share this post


Link to post
Share on other sites
Advertisement
I haven't been able to reproduce this problem.

This is the class I wrote to test it:


class CRefClass
{
public:
CRefClass()
{
refCount = 1;
}
~CRefClass()
{
}
int AddRef()
{
return ++refCount;
}
int Release()
{
int r = --refCount;
if( refCount == 0 ) delete this;
return r;
}
CRefClass &Do()
{
return *this;
}
int refCount;
};

CRefClass *Factory()
{
return new CRefClass;
}


And this is how I register it:


r = engine->RegisterObjectType("refclass", sizeof(CRefClass), asOBJ_REF); assert(r >= 0);
r = engine->RegisterObjectBehaviour("refclass", asBEHAVE_FACTORY, "refclass@ f()", asFUNCTION(Factory), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterObjectBehaviour("refclass", asBEHAVE_ADDREF, "void f()", asMETHOD(CRefClass, AddRef), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectBehaviour("refclass", asBEHAVE_RELEASE, "void f()", asMETHOD(CRefClass, Release), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod("refclass", "refclass &Do()", asMETHOD(CRefClass,Do), asCALL_THISCALL); assert(r >= 0);


This only calls Release 1 time:


r = engine->ExecuteString(0, "refclass ref; ref.Do()");


Did you perhaps register the Do() method with "refclass @Do()"? That would explains why AngelScript called Release() twice in your case.

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!