diff --git a/src/scriptInterfaceMagic.h b/src/scriptInterfaceMagic.h index 34a22bb..7029741 100644 --- a/src/scriptInterfaceMagic.h +++ b/src/scriptInterfaceMagic.h @@ -136,6 +136,11 @@ struct convert luaL_argerror(L, idx-1, msg); return; } + if (*p == NULL) + { + ptr = NULL; + return; + } ptr = dynamic_cast(***p); //printf("ObjParam: %p\n", ptr); } @@ -165,6 +170,13 @@ struct convert> luaL_argerror(L, idx-1, msg); return; } + if (*p == NULL) + { + ptr = NULL; + const char* msg = lua_pushliteral(L, "Object expected, got destroyed object"); + luaL_argerror(L, idx-1, msg); + return; + } ptr = **p; //printf("ObjParam: %p\n", ptr); } @@ -529,8 +541,10 @@ template class scriptBindObject if (lua_isuserdata(L, -1)) //When a subclass is destroyed, it's metatable might call the __gc function on it's sub-metatable. So we can get nil values here, ignore that. { PT* p = static_cast< PT* >(lua_touserdata(L, -1)); - if (*p) + if (*p) { delete *p; + *p = nullptr; + } } lua_pop(L, 1); return 0;