Description
Your Godot version: 4.1.1-stable
Issue description: It seems that GDExtension classes (i.e. those that use the GDCLASS
macro) break in surprising and non-obvious ways if instantiated in C++ with automatic storage duration (colloquially "on the stack", e.g. MyClass mine()
) or any non-memnew
-created dynamic storage duration (colloquially "on the heap", e.g. MyClass *mine = new MyClass()
). For example, their get_class
methods will not return correctly, deferred call dispatch will fail, custom signals will not work, callbacks will be missed, and so on. (See godotengine/godot-cpp#1057 and godotengine/godot#69270 for more information.)
It is not presently clear if automatic storage duration should be or will be usable in the future, but it seems wise regardless to make explicit in documentation that only when instantiated with dynamic storage duration using memnew
(e.g. MyClass *mine(memnew(MyClass))
) will these classes work as expected.
I'm not sure whether such documentation is best added to the existing GDExtension tutorial example or in some other piece of upcoming GDExtension documentation, so I leave this issue open to those in a better position to decide. Whether this should be considered a documentation bug or enhancement, likewise.
URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html