From ac9c5d0ba4ad5ae07617a1040b18aad47c4789c4 Mon Sep 17 00:00:00 2001 From: SREsAreHumanToo <88474954+sresarehumantoo@users.noreply.github.com> Date: Mon, 7 Sep 2026 22:37:00 -0400 Subject: [PATCH] fix(linux): guard XRandR NULL returns to avoid a SEGV during display setup XRRGetScreenResources and XRRGetCrtcInfo both return NULL on a transient X error, which happens while the RandR configuration is still settling (for example when a second CRTC is being brought up as a multi-display session starts). Three call sites dereference the result without checking it, so the whole process dies instead of reporting a failure the caller can retry. Check all three: both x11_attr_t::init() and x11_display_names() bail out the way the adjacent xdisplay failures already do, and the CRTC lookup falls through to the existing "record the entire virtual desktop" path. Observed on a two-display session that raced CRTC bring-up, where sunshine would SEGV on session start and succeed on retry. --- src/platform/linux/x11grab.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/platform/linux/x11grab.cpp b/src/platform/linux/x11grab.cpp index a14b3b66d09..57d57fda98c 100644 --- a/src/platform/linux/x11grab.cpp +++ b/src/platform/linux/x11grab.cpp @@ -513,6 +513,10 @@ namespace platf { } screen_res_t screenr {x11::rr::GetScreenResources(xdisplay.get(), xwindow)}; + if (!screenr) { + BOOST_LOG(error) << "Could not query X screen resources"sv; + return -1; + } int output = screenr->noutput; output_info_t result; @@ -531,8 +535,12 @@ namespace platf { } } + crtc_info_t crt_info; if (result_found && result->crtc) { - crtc_info_t crt_info {x11::rr::GetCrtcInfo(xdisplay.get(), screenr.get(), result->crtc)}; + crt_info = crtc_info_t {x11::rr::GetCrtcInfo(xdisplay.get(), screenr.get(), result->crtc)}; + } + + if (crt_info) { BOOST_LOG(info) << "Streaming display: "sv << result->name << " with res "sv << crt_info->width << 'x' << crt_info->height << " offset by "sv << crt_info->x << 'x' << crt_info->y; @@ -942,6 +950,10 @@ namespace platf { auto xwindow = DefaultRootWindow(xdisplay.get()); screen_res_t screenr {x11::rr::GetScreenResources(xdisplay.get(), xwindow)}; + if (!screenr) { + BOOST_LOG(error) << "Could not query X screen resources"sv; + return {}; + } int output = screenr->noutput; std::vector names;