flightlessmango/MangoHud

CS2 crashing at start with MangoHud

ecabott opened this issue · 9 comments

Opens without MangoHud.
Crashes at start with MangoHud.
Fedora 39
MangoHud v0.7.1

Can you please verify that it is 0.7.1 with the version option in mangohud

I can confirm that the version is 0.7.1. Here is the error log:

[🡕] Process 1885954 (mangohud) of user 1000 dumped 
Module /nix/store/7ihbjzic97238sq8bnpyyvbdygc6qdls-libxcb-1.16/lib/libxcb.so.1.1.0 without build-id.
Module /nix/store/1bapla8zwlx128i42wi08zbiibwk6gm3-libglvnd-1.7.0/lib/libGLdispatch.so.0.0.0 without build-id.
Module /nix/store/ihnkqhgq5qqgdjldq0mqg15gx134lzyb-libXext-1.3.5/lib/libXext.so.6.4.0 without build-id.
Module /nix/store/m81vwjvzw0js60ca2g1j02z30pfr68fw-libX11-1.8.7/lib/libX11.so.6.4.0 without build-id.
Module /nix/store/1bapla8zwlx128i42wi08zbiibwk6gm3-libglvnd-1.7.0/lib/libGLX.so.0.0.0 without build-id.
Module /nix/store/1bapla8zwlx128i42wi08zbiibwk6gm3-libglvnd-1.7.0/lib/libGL.so.1.7.0 without build-id.
Module libgamemodeauto.so.0 without build-id.
Stack trace of thread :
#0  0x0000000000841f0f n/a (n/a + 0x0)
ELF object binary architecture: AMD x86-64

OS: NixOS 23.11
Kernel: 6.6.23
DE: KDE Plasma 5.27.10
GPU: AMD Radeon RX 6600

Can you please verify that it is 0.7.1 with the version option in mangohud

mangohud --version outputs v0.7.1

Can't reproduce this on 0.7.1 or latest.
Do you have more information like using a different vulkan driver than radv or using flatpak?

Can't reproduce this on 0.7.1 or latest. Do you have more information like using a different vulkan driver than radv or using flatpak?

Its just default Fedora 39.

Same here. Default NixOS 23.11 with Mesa 23.1.9.

If that helps you, I found this patch:

diff --git a/bin/mangohud.in b/bin/mangohud.in
index 53c72ef..3cc4f19 100755
--- a/bin/mangohud.in
+++ b/bin/mangohud.in
@@ -13,13 +13,13 @@ fi
 DISABLE_LD_PRELOAD="cs2.sh
 some_other_exe"

-MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_opengl.so"
+MANGOHUD_LIB_NAME="libMangoHud_opengl.so"

 if [ "$1" = "--dlsym" ]; then
-    MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+    MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
     shift  # shift will only be executed if $1 is "--dlsym"
 elif [ "$MANGOHUD_DLSYM" = "1" ]; then
-    MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+    MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
 fi

 if [ "$1" = "--version" ]; then
@@ -40,8 +40,10 @@ for exe in $DISABLE_LD_PRELOAD; do
     fi
 done

+XDG_DATA_DIRS="@dataDir@${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
+
 if [ "$disable_preload" = true ]; then
-    exec env MANGOHUD=1 "$@"
+    exec env MANGOHUD=1 XDG_DATA_DIRS="${XDG_DATA_DIRS}" "$@"
 else
     # Make sure we don't append mangohud lib multiple times
     # otherwise, this could cause issues with the steam runtime
@@ -54,5 +56,7 @@ else
             LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
     esac

-    exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" "$@"
+    LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
+
+    exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" XDG_DATA_DIRS="${XDG_DATA_DIRS}" "$@"
 fi

This patch fixes the error on my side for MangoHUD 0.7.0

Same here. Default NixOS 23.11 with Mesa 23.1.9.

If that helps you, I found this patch:

diff --git a/bin/mangohud.in b/bin/mangohud.in
index 53c72ef..3cc4f19 100755
--- a/bin/mangohud.in
+++ b/bin/mangohud.in
@@ -13,13 +13,13 @@ fi
 DISABLE_LD_PRELOAD="cs2.sh
 some_other_exe"

-MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_opengl.so"
+MANGOHUD_LIB_NAME="libMangoHud_opengl.so"

 if [ "$1" = "--dlsym" ]; then
-    MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+    MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
     shift  # shift will only be executed if $1 is "--dlsym"
 elif [ "$MANGOHUD_DLSYM" = "1" ]; then
-    MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+    MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
 fi

 if [ "$1" = "--version" ]; then
@@ -40,8 +40,10 @@ for exe in $DISABLE_LD_PRELOAD; do
     fi
 done

+XDG_DATA_DIRS="@dataDir@${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
+
 if [ "$disable_preload" = true ]; then
-    exec env MANGOHUD=1 "$@"
+    exec env MANGOHUD=1 XDG_DATA_DIRS="${XDG_DATA_DIRS}" "$@"
 else
     # Make sure we don't append mangohud lib multiple times
     # otherwise, this could cause issues with the steam runtime
@@ -54,5 +56,7 @@ else
             LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
     esac

-    exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" "$@"
+    LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
+
+    exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" XDG_DATA_DIRS="${XDG_DATA_DIRS}" "$@"
 fi

This patch fixes the error on my side for MangoHUD 0.7.0

Hmm on the latest build we shouldn't be using preload at all with CS2.

Nice. In addition to that, I forgot to add another patch file. Not sure if this is related to this problem though:

diff --git a/src/dbus.cpp b/src/dbus.cpp
index 7379af1..4eef3fe 100644
--- a/src/dbus.cpp
+++ b/src/dbus.cpp
@@ -152,7 +152,7 @@ bool dbus_manager::get_media_player_metadata(metadata& meta, std::string name) {
 }

 bool dbus_manager::init_internal() {
-    if (!m_dbus_ldr.IsLoaded() && !m_dbus_ldr.Load("libdbus-1.so.3")) {
+    if (!m_dbus_ldr.IsLoaded() && !m_dbus_ldr.Load("@libdbus@/lib/libdbus-1.so.3")) {
         SPDLOG_ERROR("Could not load libdbus-1.so.3");
         return false;
     }
diff --git a/src/logging.cpp b/src/logging.cpp
index 046c847..42782be 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -26,7 +26,11 @@ string exec(string command) {
 #endif
     std::array<char, 128> buffer;
     std::string result;
+
+    char* originalPath = getenv("PATH");
+    setenv("PATH", "@path@", 1);
     std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
+    setenv("PATH", originalPath, 1);
     if (!pipe) {
       return "popen failed!";
     }
diff --git a/src/pci_ids.cpp b/src/pci_ids.cpp
index 002a843..5a6262b 100644
--- a/src/pci_ids.cpp
+++ b/src/pci_ids.cpp
@@ -24,11 +24,9 @@ static std::istream& get_uncommented_line(std::istream& is, std::string &line)
 void parse_pciids()
 {
     std::ifstream file;
-    file.open("/usr/share/hwdata/pci.ids");
+    file.open("@hwdata@/share/hwdata/pci.ids");
     if (file.fail()){
-        file.open("/usr/share/misc/pci.ids");
-        if (file.fail())
-            SPDLOG_ERROR("can't find file pci.ids");
+        SPDLOG_ERROR("can't find file pci.ids");
     }

     std::string line;

I just found this approach from another repository and this was the only one that makes MangoHUD works for me.

I don't think it's useful to muddle this by patching an old version of mangohud