Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance binding data on GDNativeLibrary objects never gets freed #39181

Open
Zylann opened this issue May 30, 2020 · 0 comments
Open

Instance binding data on GDNativeLibrary objects never gets freed #39181

Zylann opened this issue May 30, 2020 · 0 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented May 30, 2020

Godot 3.2.2 beta3
Windows 10 64 bits

Object instances can hold GDNative instance binding data (for example, that data can correspond to class wrappers inside of NativeScript libraries). This data is normally freed in the destructor of Object... unless ScriptServer::finish_languages(); is called before. In such case the data will leak.

Turns out that's the case I found.
In C++ bindings, we access our own GDNativeLibrary here: https://github.com/GodotNativeTools/godot-cpp/blob/e97e86648355cbe61c6249483c6f2a5d1b41714f/include/core/Godot.hpp#L43

This leads to instance binding data being attached (only the first time) to the object.
Unfortunately, it never gets freed, because on quit, things happen in this order:

  • ScriptServer::finish_languages();
  • Our GDNative library gets terminated
  • Godot deletes the GDNativeLibrary

By extension, it also means if a library wants to hold a Godot object as internal singleton (like it happens sometimes in modules), the instance binding data of such objects will always leak, even if the object is freed in the terminate callback.

Eventually there should be an error printed when stuff like that happens, because currently it's completely silent and I had to investigate for a while.

In the C++ bindings we might be able to workaround this by avoiding the use of instance binding data (so, using the C API directly without any helper). Wether this should be allowed or not I don't know, but it looks like a bug from Godot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants