|Topic was automatically imported from the old Question2Answer platform.
Is there any way to make sure that c++ class’s destructor is certainly called in GDNative module? Regardless of the module being added in scene tree or not?
Can’t you rephrase your question?
Normally you add your class as node’s script, then ctor and init() is called.
When you free object then dtor are called.
sash-rc | 2020-10-20 18:42
Yes, your answer is correct for most of times, but maybe a c++ script is not meant to be added to any node and is used simply by making a new object using new() method. I know that in this case the developer is responsible for freeing that object, but what i actually was looking for was a way to find out that the application is closing (quiting or whatever) or a signal that shows this. Then in _init function of c++ script, it would be possible to connect that signal to the free() method and so in this case we can say for certain that the dtor will be called even if the developer forgets to call the free() method.
alireza49 | 2020-10-20 19:53
Well, still didn’t get your exact use-case, but there’s a
godot_gdnative_terminate (alongside with
godot_gdnative_init), so you can handle your custom deallocations there.
Personally, for similar purpose I use Autoload singleton Node, where I destroy my stuff not related to scene tree (in it’s dtor). Also, it looks it’s possible to hook to
sash-rc | 2020-10-20 23:07