Hey,
I have a feeling I am doing something wrong. My code technically works but my destructor isn't called when I expect it to be so I figured I would check with you just to be sure.
So I have a small value type class that is exposed to AS. I looked at the registration code for std::string in the string addon and pretty much copied it for my own type. The registration is done like this:
namespace
{
void construct(StringHash h, GameObjectRef* mem)
{
new(mem) GameObjectRef(h);
}
void destruct(GameObjectRef* pointer)
{
pointer->~GameObjectRef();
}
}
int r = scriptEngine->RegisterObjectType("gameobject", sizeof(GameObjectRef), asOBJ_VALUE | asGetTypeTraits<GameObjectRef>()); ASSERT(r >= 0);
r = scriptEngine->RegisterObjectBehaviour("gameobject", asBEHAVE_CONSTRUCT, "void f(uint)", asFUNCTION(construct), asCALL_CDECL_OBJLAST); ASSERT(r >= 0);
r = scriptEngine->RegisterObjectBehaviour("gameobject", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(destruct), asCALL_CDECL_OBJLAST); ASSERT(r >= 0);
I then have a small function in AS which is run every frame:
void test()
{
gameobject test("123");
}
With this setup the construct() function is run and the object is properly created but the destruct() function is never run, not even when shutting down the app. I tried registering the type with the POD flag too, but that did not help. I am using AS version 2.30.2.