• Advertisement
Sign in to follow this  

Constructor with parameters assert

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

This is the code to reproduce (based on test_constructor.cpp 1.9.2) :
class CMyObj {
public :
	CMyObj() {};
	virtual ~CMyObj() {};
};

void ConstrMyObj(CMyObj &obj)
{
	new(&obj) CMyObj();
}

void DestrMyObj(CMyObj &obj)
{
	obj.~CMyObj();
}

class CMySecondObj {
	CMyObj *m_myObj;
public :
	CMySecondObj(CMyObj *in_myObj = NULL) {m_myObj = in_myObj;};
	virtual ~CMySecondObj()  {};
};

void ConstrMySecondObj(CMySecondObj &obj)
{
	new(&obj) CMySecondObj();
}

void ConstrMySecondObj(CMyObj &o, CMySecondObj &obj)
{
	new(&obj) CMySecondObj(&o);
}

void DestrMySecondObj(CMySecondObj &obj)
{
	obj.~CMySecondObj();
}

bool TestConstructor()
{
	bool fail = false;

	asIScriptEngine *engine;
	int r;
	engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	r = engine->RegisterObjectType("MyObj", sizeof(CMyObj), asOBJ_CLASS); assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("MyObj", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstrMyObj), asCALL_CDECL_OBJLAST); assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("MyObj", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestrMyObj), asCALL_CDECL_OBJLAST); assert( r >= 0 );

	r = engine->RegisterObjectType("MySecondObj", sizeof(CMySecondObj), asOBJ_CLASS); assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("MySecondObj", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONP(ConstrMySecondObj, (CMySecondObj &)), asCALL_CDECL_OBJLAST);
	assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("MySecondObj", asBEHAVE_CONSTRUCT, "void f(MyObj& in_myObj)", asFUNCTIONP(ConstrMySecondObj, (CMyObj &, CMySecondObj &)), asCALL_CDECL_OBJLAST);
	assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("MySecondObj", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestrMySecondObj), asCALL_CDECL_OBJLAST); assert( r >= 0 );
	
	engine->ExecuteString(0, "MyObj obj; {MySecondObj secObj(obj);}");
	engine->Release();


	// Success
	return fail;
}





At ExecuteString you get an assert caused by as_bytecode.cpp at line 563 (
// Make sure we found a destructor
				assert( n < destructors.GetLength() );
because n = 1 and destructors.length = 1. Regards, AbrKen. Oops, I forgot to mention that ignoring the assert is ok, the program gently terminate. Oops 2, ignoring the assert only work with my big application !? [Edited by - abrken on October 12, 2004 4:46:33 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement