From ec07763f49050f0a48876c157384d36d87e73f1b Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Thu, 23 Jan 2025 13:00:02 -0500 Subject: [PATCH] Wayland Backend: fix issue w/ steam notification window causing gamescope to crash --- src/Backends/WaylandBackend.cpp | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp index 08af8bca1b..05e92af404 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -182,6 +182,39 @@ namespace gamescope return outState; } + inline bool BPlaneHasValidGeometry(const std::optional &oState) + { + // valid values for: + // - src: + // width & height: -1 or > 0 + // x & y: -1 or >= 0 + // - dst: + // width & height: -1 or > 0 + // x & y: INT_MIN to INT_MAX (no restriction) + // + // For our purposes, we won't treat src{X,Y,Width,Height} or + // dst{Width,Height} values of -1 as valid Since we'll never set those + // aforementioned geometry components to -1 while still intending to + // present the plane + if (!oState) { + return false; + } + const double epsilon = 0.001; // same epsilon value used in close_enough() + const double slightlyAboveZero = 0.0 + epsilon; // avoid any possible floating point comparison weirdness + if (oState->flSrcX < 0.0 || oState->flSrcY < 0.0 + || oState->flSrcWidth < slightlyAboveZero + || oState->flSrcHeight < slightlyAboveZero) + { + return false; + } + + if (oState->nDstWidth <= 0 || oState->nDstHeight <= 0) + { + return false; + } + return true; + } + class CWaylandPlane { public: @@ -981,7 +1014,7 @@ namespace gamescope m_oCurrentPlaneState = oState; } - if ( oState ) + if ( BPlaneHasValidGeometry(oState) ) { assert( oState->pBuffer ); @@ -1020,7 +1053,6 @@ namespace gamescope break; } } - // Fraction with denominator of 120 per. spec const uint32_t uScale = oState->uFractionalScale;