Handling exceptions and printing to std::cout from GDExtension causes crashes
Description:
This bug has been reported by multiple people (including me) in different ways in the Godot repositories. After some testing, we realized that what we have in common is an Arch-based system, and we could confirm that the issue occurs only with the Arch package of Godot v4.2 or above, not with Godot's provided builds of the editor or a manually compiled editor. It also did not occur with the Godot arch packages below v4.2.
Something is wrong with how this build interacts with GDExtension plugins, i.e. manually compiled additional C++ modules imported by the engine. This manifests itself in multiple different ways when using a custom GDExtension, but presumably all of these have the same cause:
Exception handling: When throwing and catching exceptions in GDExtension code which is called in the Godot project, the editor crashes with SIGABRT. See https://github.com/godotengine/godot-cpp/issues/1326 for more detail and a reproduction project.
Printing via std::cout
: When doing a simple std::cout << "Hello World" << std::endl;
in GDExtension code, the editor crashes with SIGSEGV instead of printing to the console. printf
works.
See https://github.com/godotengine/godot-cpp/issues/1341 and https://github.com/godotengine/godot/issues/85959 for more detail and reproduction projects.
Presumably, there is a general issue when using std
library functionality in GDExtensions from the Arch godot build. I also noticed other crashes in my GDExtension which were terrible to debug, but seemed to be related to the use of std
containers.
I can't tell what it is though, since from what I can tell, nothing changed here in the upgrade to v4.2. Godot's default compilation flags should not cause this issue.
Additional info:
- package version(s): v4.2 and up
- config and/or log files: see linked GitHub issues above
- link to upstream bug report, if any: see linked GitHub issues above
Steps to reproduce:
see linked GitHub issues above