Repository: godot
Issue: MangoHUD crashes Godot on startup in self-compiled builds only
Labels: bug,platform:linuxbsd,topic:rendering,topic:thirdparty,crash

### Godot version

4.0.1.stable (self-compiled), 4.1.dev 2a275b985ef8a2af9ad07a3572bcfe693f58b7c1, 4.3.dev 8f0c20ee8

### System information

Fedora 37, GeForce RTX 4090 (NVIDIA 525.89.02)

### Issue description

MangoHud crashes Godot on startup in self-compiled builds only. This does not occur with official Godot 4.0 or 4.0.1 binaries.

The editor and project manager aren't affected by this issue, as they forcibly disable MangoHud. The Compatibility renderer also doesn't exhibit this issue, as MangoHud cannot be implicitly loaded in OpenGL applications (you must run it with `mangohud`). I can't get MangoHud to show up when using the Compatibiity rendering method and running Godot with `mangohud`, but that's a separate issue.

See https://github.com/godotengine/godot/issues/74182#issuecomment-1452776982 where I originally found this.

I'm using MangoHud 0.6.8 from Fedora repositories, globally injected as a Vulkan layer (so I don't need to run every game with `mangohud` to be able to pop up the overlay).

The MangoHud configuration file *does* exist, and MangoHUD displays correctly on official Godot builds (and in other Vulkan applications).

When running from a terminal, output looks like this:

```
$ bin/godot.linuxbsd.editor.x86_64 --path ~/Documents/Godot/godot-reflection/
Godot Engine v4.1.dev.custom_build.2a275b985 - https://godotengine.org
[2023-03-28 03:56:03.400] [MANGOHUD] [info] [config.cpp:118] skipping config: '/home/hugo/Documents/Git/godotengine/godot/bin/MangoHud.conf' [ not found ]
[2023-03-28 03:56:03.400] [MANGOHUD] [info] [config.cpp:118] skipping config: '/home/hugo/.config/MangoHud/godot.linuxbsd.editor.x86_64.conf' [ not found ]
[2023-03-28 03:56:03.400] [MANGOHUD] [info] [config.cpp:123] parsing config: '/home/hugo/.config/MangoHud/MangoHud.conf'
free(): invalid pointer
[1]    89142 IOT instruction (core dumped)  bin/godot.linuxbsd.editor.x86_64 --path ~/Documents/Godot/godot-reflection/
```

This can be worked around by using `export MANGOHUD=0` before running Godot, which disables MangoHUD as expected.

### Backtrace 

```cpp
#0  0x00007ffff70afe5c in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007ffff705fa76 in raise () from /lib64/libc.so.6
#2  0x00007ffff70497fc in abort () from /lib64/libc.so.6
#3  0x00007ffff70a408e in __libc_message () from /lib64/libc.so.6
#4  0x00007ffff70b9b9c in malloc_printerr () from /lib64/libc.so.6
#5  0x00007ffff70bb9dc in _int_free () from /lib64/libc.so.6
#6  0x00007ffff70be363 in free () from /lib64/libc.so.6
#7  0x0000000009558ada in std::locale::_Impl::~_Impl() ()
#8  0x0000000009558d26 in std::locale::~locale() ()
#9  0x00007fffd46a0b38 in parseConfigFile(overlay_params&) () from /usr/lib64/mangohud/libMangoHud.so
#10 0x00007fffd469a06a in parse_overlay_config () from /usr/lib64/mangohud/libMangoHud.so
#11 0x00007fffd46b140b in overlay_CreateInstance(VkInstanceCreateInfo const*, VkAllocationCallbacks const*, VkInstance_T**) ()
   from /usr/lib64/mangohud/libMangoHud.so
#12 0x00007fffd55a59d0 in loader_create_instance_chain () from /lib64/libvulkan.so.1
#13 0x00007fffd55ba1f3 in vkCreateInstance () from /lib64/libvulkan.so.1
#14 0x0000000003c59aad in VulkanContext::_create_instance (this=0xb09eac0) at drivers/vulkan/vulkan_context.cpp:1042
#15 0x0000000003c5ea69 in VulkanContext::initialize (this=0xb09eac0) at drivers/vulkan/vulkan_context.cpp:2173
#16 0x000000000267b07b in DisplayServerX11::DisplayServerX11 (this=0xb035c50, p_rendering_driver=..., 
    p_mode=DisplayServer::WINDOW_MODE_WINDOWED, p_vsync_mode=DisplayServer::VSYNC_ENABLED, p_flags=0, p_position=0x0, 
    p_resolution=..., p_screen=-2, r_error=@0x7fffffff7ffc: OK) at platform/linuxbsd/x11/display_server_x11.cpp:5485
#17 0x0000000002678499 in DisplayServerX11::create_func (p_rendering_driver=..., p_mode=DisplayServer::WINDOW_MODE_WINDOWED, 
    p_vsync_mode=DisplayServer::VSYNC_ENABLED, p_flags=0, p_position=0x0, p_resolution=..., p_screen=-2, r_error=@0x7fffffff7ffc: OK)
    at platform/linuxbsd/x11/display_server_x11.cpp:4869
#18 0x000000000726b54e in DisplayServer::create (p_index=0, p_rendering_driver=..., p_mode=DisplayServer::WINDOW_MODE_WINDOWED, 
    p_vsync_mode=DisplayServer::VSYNC_ENABLED, p_flags=0, p_position=0x0, p_resolution=..., p_screen=-2, r_error=@0x7fffffff7ffc: OK)
    at servers/display_server.cpp:906
#19 0x00000000026d766f in Main::setup2 (p_main_tid_override=0) at main/main.cpp:2001
#20 0x00000000026d3406 in Main::setup (
    execpath=0x7fffffffd10a "/home/hugo/Documents/Git/godotengine/godot/bin/godot.linuxbsd.editor.x86_64", argc=2, 
    argv=0x7fffffffcbc0, p_second_phase=true) at main/main.cpp:1879
#21 0x0000000002643e05 in main (argc=3, argv=0x7fffffffcbb8) at platform/linuxbsd/godot_linuxbsd.cpp:61
```

### Steps to reproduce

- Install [MangoHud](https://github.com/flightlessmango/MangoHud)
- Run a project that uses Forward+ or Mobile rendering method from the editor, or directly from the command line.

### Minimal reproduction project

https://github.com/Calinou/godot-reflection