godotengine / godot

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

GDExtension libraries that use `std::call_once` during static initialization crash Godot editor with `freetype, libpng, zlib, graphite, harfbuzz` as system-provided #91401

Closed j20001970 closed 3 weeks ago

j20001970 commented 6 months ago

Tested versions

Reproducible in recent Godot 4.x version (latest attempt is v4.4.dev.custom_build [1fc820876]) that uses system-provided freetype, libpng, zlib, graphite, harfbuzz libraries.

System information

Godot v4.4.dev (1fc820876) - Freedesktop SDK 23.08 (Flatpak runtime) on Wayland - Wayland display driver, Single-window, 1 monitor - Vulkan (Forward+) - dedicated AMD Radeon RX 6650 XT (RADV NAVI23) - 12th Gen Intel(R) Core(TM) i5-12500 (12 threads)

The problem is found when developing GDExtension libraries on Linux, not sure if it also occur on other platforms.

Issue description

If Godot editor is using system-provided freetype, libpng, zlib, graphite, harfbuzz libraries instead of built-in, opening projects with GDExtension libraries that uses std::call_once during static initialization will crash the editor.

While official Godot editor will work without problems as it has everything builtin, many custom builds including Linux distribution packages (for example Arch and Flathub) configure Godot to use these libraries as system-provided, resulting in said GDExtension libraries unusable in custom Godot editor builds.

However, if the GDExtension library is preloaded with LD_PRELOAD environment variable, the editor will open the project without any issues.

Steps to reproduce

  1. Clone the MRP project.
  2. Build example GDExtension library with scons.
  3. Open the project with Godot editor that has every libraries builtin.
  4. The project opens successfully, once called will appear on stdout.
  5. Open the project with Godot editor that uses system-provided freetype, libpng, zlib, graphite, harfbuzz.
  6. Editor crashed with signal 11.

Minimal reproduction project (MRP)

https://github.com/j20001970/godot_static_call_once_crash

j20001970 commented 1 month ago

After some investigation of the issue, I think I managed to narrow down the problem for a bit, and the bug report has been updated.

Honestly I do not know if this is Godot-side or Protobuf-side problem, and is way beyond my skill.

j20001970 commented 1 month ago

Update: I've once again narrow down the problem, and maybe found the actual root cause for real this time.

I'm curious that does Godot team receive notification when bug report is updated?

Zireael07 commented 1 month ago

@j20001970 Everyone who watches the repository receives notification when someone comments.

j20001970 commented 1 month ago

I think this issue is related to GDExtension though it has no topic:gdextension label, can you please update the label so this issue can have better visibility? Thank you.