From a59d58557637e54b266216dfc029aa208e792297 Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:58:08 -0500 Subject: [PATCH] steamcompmgr: fix another coredump-at-exit --- src/backend.cpp | 22 +++++++++++----------- src/steamcompmgr.cpp | 27 ++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index 8a6bbe8ed9..a15e0e5051 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -16,34 +16,34 @@ namespace gamescope // IBackend ///////////// - static IBackend *s_pBackend = nullptr; + static std::atomic s_pBackend = nullptr; IBackend *IBackend::Get() { return s_pBackend; } - + + bool IBackend::Set( IBackend *pBackend ) { - if ( s_pBackend ) - { - delete s_pBackend; - s_pBackend = nullptr; - } + //FIXME: calling the backend's destructor sometimes hangs gamescope for wayland backend + //if ( s_pBackend ) { + // std::destroy_at(GetBackend()); + //} if ( pBackend ) { s_pBackend = pBackend; - if ( !s_pBackend->Init() ) + if ( !GetBackend()->Init() ) { - delete s_pBackend; - s_pBackend = nullptr; + s_pBackend = nullptr; return false; } } return true; } + ///////////////// // CBaseBackendFb @@ -184,4 +184,4 @@ namespace gamescope GetBackend()->DumpDebugInfo(); }); -} +} \ No newline at end of file diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 11a7cade6c..76fdefcbeb 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -5896,8 +5896,25 @@ error(Display *dpy, XErrorEvent *ev) } [[noreturn]] static void -steamcompmgr_exit(void) +steamcompmgr_exit(std::optional> lock = std::nullopt) { + + // Need to clear all the vk_lutxd references (which can be tied to backend-allocated memory) + // for the colormgmt globals/statics, to avoid coredump at exit from within the colormgmt exit-time destructors: + for (auto& colorMgmtArr : + { + std::ref(g_ColorMgmtLuts), + std::ref(g_ColorMgmtLutsOverride), + std::ref(g_ScreenshotColorMgmtLuts), + std::ref(g_ScreenshotColorMgmtLutsHDR) + }) + { + for (auto& colorMgmt : colorMgmtArr.get()) + { + colorMgmt.gamescope_color_mgmt_luts::~gamescope_color_mgmt_luts(); //dtor call also calls all the subobjects' dtors + } + } + g_ImageWaiter.Shutdown(); // Clean up any commits. @@ -5922,7 +5939,6 @@ steamcompmgr_exit(void) { g_ColorMgmt.pending.appHDRMetadata = nullptr; g_ColorMgmt.current.appHDRMetadata = nullptr; - s_scRGB709To2020Matrix = nullptr; for (int i = 0; i < gamescope::GAMESCOPE_SCREEN_TYPE_COUNT; i++) { @@ -5930,13 +5946,14 @@ steamcompmgr_exit(void) s_MuraCTMBlob[i] = nullptr; } } - + if (lock) + lock->unlock(); gamescope::IBackend::Set( nullptr ); wlserver_lock(); wlserver_shutdown(); wlserver_unlock(false); - + pthread_exit(NULL); } @@ -8042,7 +8059,7 @@ steamcompmgr_main(int argc, char **argv) vblank = false; } - steamcompmgr_exit(); + steamcompmgr_exit(std::optional> {std::in_place_t{}, std::move(xwayland_server_guard)} ); } void steamcompmgr_send_frame_done_to_focus_window()