godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.68k stars 20.11k forks source link

Godot silently crashes if no _init is specified in GDNative class #52511

Open 0x0ACB opened 2 years ago

0x0ACB commented 2 years ago

Godot version

Godot_v3.3.3-stable_win64

System information

Windows 10

Issue description

It is perfectly possible to compile a GDNative C++ class that does not define a _init method without any warnings or compile errors. However once the class gets instantiated like this:

onready var test = preload("res://bin/test.gdns").new()

the game will just silently exit without any warnings, logs or errors to indicate a crash. The crash happens in this method in Object.cpp

void Object::_init() {
    ___godot_icall_void(___mb.mb__init, (const Object *) this);
}

where ___mb is a nullptr resulting in an obvious nullptr exception that (without a debugger attached) gets silently discarded and crashes the engine.

Steps to reproduce

Create GDNative class without _init method and then try to instantiate it.

Minimal reproduction project

No response

Zylann commented 2 years ago

More info here: https://github.com/godotengine/godot-cpp/issues/348#issuecomment-742084113 I'm curious if GDExtensions also have this. The likely do, since the technique used for wrapper classes didnt change AFAIK.

Note: C++ in general silently crashes for plenty other reasons, if you run it without a debugger. It ain't like GDScript where a debugger is always running in the editor. Using a debugger will almost never let crashes happen silently.