diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index 15ebc4ea4fe6..8844acdb11c9 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -128,6 +128,11 @@ stdenv.mkDerivation (finalAttrs: { libdbus = dbus.lib; inherit hwdata; }) + + # Fix crash when starting hidden + # Upstream PR: https://github.com/flightlessmango/MangoHud/pull/1570 + # FIXME: remove when merged + ./fix-crash.patch ]; postPatch = '' diff --git a/pkgs/tools/graphics/mangohud/fix-crash.patch b/pkgs/tools/graphics/mangohud/fix-crash.patch new file mode 100644 index 000000000000..e25d953f300d --- /dev/null +++ b/pkgs/tools/graphics/mangohud/fix-crash.patch @@ -0,0 +1,40 @@ +From f0d7e4f4b2d362d90bb81d0b10ef5c505b9661ea Mon Sep 17 00:00:00 2001 +From: K900 +Date: Fri, 14 Feb 2025 11:41:09 +0300 +Subject: [PATCH] mangoapp: don't crash if gpus is not initialized yet + +This seems to happen on startup on Steam Deck style gamescope-session setups. +Just check for gpus = null before trying to access it. +--- + src/app/main.cpp | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/src/app/main.cpp b/src/app/main.cpp +index 0c7c13e07e..4d1d3b1277 100644 +--- a/src/app/main.cpp ++++ b/src/app/main.cpp +@@ -369,8 +369,9 @@ int main(int, char**) + XSync(x11_display, 0); + mangoapp_paused = false; + // resume all GPU threads +- for (auto gpu : gpus->available_gpus) +- gpu->resume(); ++ if (gpus) ++ for (auto gpu : gpus->available_gpus) ++ gpu->resume(); + } + { + std::unique_lock lk(mangoapp_m); +@@ -409,8 +410,9 @@ int main(int, char**) + XSync(x11_display, 0); + mangoapp_paused = true; + // pause all GPUs threads +- for (auto gpu : gpus->available_gpus) +- gpu->pause(); ++ if (gpus) ++ for (auto gpu : gpus->available_gpus) ++ gpu->pause(); + + // If mangoapp is hidden, using mangoapp_cv.wait() causes a hang. + // Because of this hang, we can't detect if the user presses R_SHIFT + F12, +