godot: Crash during engine shutdown if `get_tree()` is ever called from GDNative
Godot version: 3.3 stable
OS/device including version: Windows 10
Issue description:
If get_tree()
is ever called from a GDNative plugin then Godot will crash on shutdown when you quit your game.
The crash occurs in NativeScriptLanguage::free_instance_binding_data
.
free_instance_binding_data
is entered but godot_gdnative_terminate
has already been called at this point so the function pointer is invalid.
This doesn’t happen in Godot 3.2.
Steps to reproduce:
Call get_tree()
from a GDNative class, run your game with a debugger attached and quit.
Minimal reproduction project: gdnative_get_tree_crash.zip
This is the only relevant part AFAIK:
class Test : public godot::Node {
GODOT_CLASS(Test, godot::Node);
public:
static void _register_methods() {
register_method("_ready", &Test::_ready);
}
void _init(){}
void _ready() {
get_tree();
// Godot will now crash in NativeScriptLanguage::free_instance_binding_data()
}
};
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 23 (9 by maintainers)
Commits related to this issue
- Workaround for crash from known bug: https://github.com/godotengine/godot/issues/48295 — committed to NovaZHart/ShooterPrototype by NovaZHart 2 years ago
- Hotfix: calling get_tree() caused crash on quit see https://github.com/godotengine/godot/issues/48295#issuecomment-981404421 — committed to jacogasp/aphs by jacogasp 2 years ago
It appears this workaround can be added to user code to suppress the crash
I tried again and I finally managed to reproduce the crash on Linux. It doesn’t seem to happen when running the project through the editor, but it does when running standalone.
Here’s a fixed MRP so that it builds properly against
godot-cpp
godot-3.3.3-stable
(with renamedgodot_headers
togodot-headers
, and fixed path for Linux library).gdnative_get_tree_crash.zip
How to use:
Crash backtrace (from 3.3.4 RC e4df8a68fa9d2e35c1710dd952b1f9337e7e2f46, but that’s close enough to 3.3.3 stable):
Note that godot-cpp hasn’t been updated yet to match the
3.3-stable
release, so that may be part of the problem.This might get solved once this update is done.
Is there any effort towards figuring out how to synchronize this stuff better? It sounds like there is always going to be a window of several weeks after every Godot release where c++ projects are not going to work. Frustrating for existing developers who do not realise that they need to wait for godot-cpp to catch up, and confusing for new c++ developers who are simply following the instructions in the godot-cpp readme.
I can confirm this happens with godot-cpp (Win10 + MSVC, using the cpp gdnative-demos codebase) but doesn’t happen with godot-nim or with the C godot-headers. I only have basic familiarity with godot-cpp, but I’ll try to help debug this.