From 5c2ad3f14d54ad1f4566103ecd4d8bb0bdb5c15b Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:18:58 -0500 Subject: [PATCH] Fix coredump(s) at exit --- src/Backends/SDLBackend.cpp | 12 ++++++++++++ src/backend.cpp | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Backends/SDLBackend.cpp b/src/Backends/SDLBackend.cpp index 6d50f8d34e..d34cb74717 100644 --- a/src/Backends/SDLBackend.cpp +++ b/src/Backends/SDLBackend.cpp @@ -55,6 +55,7 @@ namespace gamescope GAMESCOPE_SDL_EVENT_CURSOR, GAMESCOPE_SDL_EVENT_COUNT, + GAMESCOPE_SDL_EVENT_REQ_EXIT, }; class CSDLConnector final : public IBackendConnector @@ -113,6 +114,7 @@ namespace gamescope { public: CSDLBackend(); + ~CSDLBackend(); ///////////// // IBackend @@ -515,6 +517,12 @@ namespace gamescope // Do nothing. } + CSDLBackend::~CSDLBackend() + { + PushUserEvent(GAMESCOPE_SDL_EVENT_REQ_EXIT); + m_SDLThread.join(); + } + void CSDLBackend::SDLThreadFunc() { pthread_setname_np( pthread_self(), "gamescope-sdl" ); @@ -912,6 +920,10 @@ namespace gamescope SDL_SetCursor( m_pCursor ); } + else if ( event.type == GetUserEventIndex( GAMESCOPE_SDL_EVENT_REQ_EXIT ) ) + { + return; + } } break; } diff --git a/src/backend.cpp b/src/backend.cpp index 8a6bbe8ed9..faf0336e5a 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -27,8 +27,7 @@ namespace gamescope { if ( s_pBackend ) { - delete s_pBackend; - s_pBackend = nullptr; + std::destroy_at(s_pBackend); } if ( pBackend )