Skip to content

Commit

Permalink
steamcompmgr: fix another coredump-at-exit
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkautarch committed Dec 12, 2024
1 parent 5cdf460 commit a59d585
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
22 changes: 11 additions & 11 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ namespace gamescope
// IBackend
/////////////

static IBackend *s_pBackend = nullptr;
static std::atomic<IBackend*> 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
Expand Down Expand Up @@ -184,4 +184,4 @@ namespace gamescope

GetBackend()->DumpDebugInfo();
});
}
}
27 changes: 22 additions & 5 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5896,8 +5896,25 @@ error(Display *dpy, XErrorEvent *ev)
}

[[noreturn]] static void
steamcompmgr_exit(void)
steamcompmgr_exit(std::optional<std::unique_lock<std::mutex>> 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.
Expand All @@ -5922,21 +5939,21 @@ 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++)
{
s_MuraCorrectionImage[i] = nullptr;
s_MuraCTMBlob[i] = nullptr;
}
}

if (lock)
lock->unlock();
gamescope::IBackend::Set( nullptr );

wlserver_lock();
wlserver_shutdown();
wlserver_unlock(false);

pthread_exit(NULL);
}

Expand Down Expand Up @@ -8042,7 +8059,7 @@ steamcompmgr_main(int argc, char **argv)
vblank = false;
}

steamcompmgr_exit();
steamcompmgr_exit(std::optional<std::unique_lock<std::mutex>> {std::in_place_t{}, std::move(xwayland_server_guard)} );
}

void steamcompmgr_send_frame_done_to_focus_window()
Expand Down

0 comments on commit a59d585

Please sign in to comment.