diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index ffd0783da..b50e79098 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -2669,7 +2669,8 @@ bool acquire_next_image( void ) } -static std::atomic g_currentPresentWaitId = {0u}; +inline std::atomic g_currentPresentWaitId = {0u}; +inline std::atomic g_presentThreadShouldExit = {false}; static std::mutex present_wait_lock; extern void mangoapp_output_update( uint64_t vblanktime ); @@ -2693,6 +2694,9 @@ static void present_wait_thread_func( void ) uint64_t vblanktime = get_time_in_nanos(); GetVBlankTimer().MarkVBlank( vblanktime, true ); mangoapp_output_update( vblanktime ); + } else if ( g_presentThreadShouldExit.load(std::memory_order_acquire)) { + g_presentThreadShouldExit = 0; + return; } } } diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index 177468228..a2e0dd972 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp @@ -74,6 +74,10 @@ enum EStreamColorspace : int #include #include +extern std::atomic g_currentPresentWaitId; + +extern std::atomic g_presentThreadShouldExit; + struct VulkanRenderer_t { struct wlr_renderer base; diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 910ed3912..f6539829e 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -5840,6 +5840,14 @@ steamcompmgr_exit(void) } } + //request the present_wait thread to exit + //needed to avoid getting a segfault at exit due to race condition: + g_presentThreadShouldExit.store(true, std::memory_order_release); + g_currentPresentWaitId = 0; //present thread will check if it should exit if this is zero + g_currentPresentWaitId.notify_all(); + g_presentThreadShouldExit.wait(true); //present thread will toggle this atomic when it sees the exit request + //this allows us to wait for present thread to close before deleting the backend + gamescope::IBackend::Set( nullptr ); wlserver_lock();