Sign in to follow this  

Pod type and Null pointer exception - bug with call destructor

Recommended Posts


I find bug [img][/img]

if comment this code

// null_object.Do();

destructor call 2 times - it is ok!

but, if we have null pointer exception

destructor call 3 times and c++ crash


Share this post

Link to post
Share on other sites
I haven't been able to reproduce this problem. I wrote the following test:

COutStream out;
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
engine->RegisterObjectType("TestLink", sizeof(CObject), asOBJ_VALUE | asOBJ_APP_CLASS_CD);
engine->RegisterObjectBehaviour("TestLink", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Construct), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("TestLink", asBEHAVE_CONSTRUCT, "void f(const TestLink &in)", asFUNCTION(CopyConstruct), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("TestLink", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destruct), asCALL_CDECL_OBJLAST);
asIScriptModule *mod = engine->GetModule("mod", asGM_ALWAYS_CREATE);
"class Object3 \n"
"{ \n"
" Object3( TestLink str ) \n"
" { \n"
" Object3 @null_object = null; \n"
" null_object.Do(); \n"
" } \n"
" void Do() {} \n"
"} \n"
"void Main() \n"
"{ \n"
" Object3 @oo = Object3( TestLink() ); \n"
"} \n");
r = mod->Build();
if( r < 0 )
CObject_constructCount = 0;
CObject_destructCount = 0;
asIScriptContext *ctx = engine->CreateContext();
r = ExecuteString(engine, "Main()", mod, ctx);
if( CObject_constructCount != 2 ||
CObject_destructCount != 1 )
if( CObject_constructCount != 2 ||
CObject_destructCount != 2 )

Share this post

Link to post
Share on other sites
FDsagizi, when you say "Pod type", do you mean that the type is registered with asOBJ_CLASS_POD? POD types aren't allowed to have user-defined destructors.

Not sure if that's relevant, but it might be confusing the compiler.

Share this post

Link to post
Share on other sites

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