Advertisement

I found an reference bug in angelscript.

Started by March 05, 2008 04:27 AM
6 comments, last by zopenge 16 years, 8 months ago
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 )
Thanks, I'll look into it.

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

Advertisement
Is the next version will be fixed it ? ( if the bug is true ) :)
If I can reproduce the bug I'll fix it for the next version.

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

That's no problem when I use asIScriptGeneric function style. :)
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.

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

Advertisement
Oh, thanks !
I will check my code :~)
The problem is fixed , thank you very much :)

This topic is closed to new replies.

Advertisement