godotengine / godotengine/godot-docs
GDExtension docs should mention that instantiating GDCLASS-inclusive classes from C++ without using memnew will break signals, deferred calls, get_class(), etc.
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.