From eee0876c7408d0fc04e999158114fca83cb5a389 Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:48:07 -0500 Subject: [PATCH] Wayland Backend: fix issue w/ steam notification window causing gamescope to crash --- src/Backends/WaylandBackend.cpp | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp index 08af8bca1b..d1fb6f2f1f 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -166,6 +166,8 @@ namespace gamescope bool bOpaque; uint32_t uFractionalScale; }; + + inline WaylandPlaneState ClipPlane( const WaylandPlaneState &state ) { @@ -181,6 +183,39 @@ namespace gamescope outState.flSrcHeight = flClippedSrcHeight; 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 { @@ -981,7 +1016,7 @@ namespace gamescope m_oCurrentPlaneState = oState; } - if ( oState ) + if ( BPlaneHasValidGeometry(oState) ) { assert( oState->pBuffer ); @@ -1020,7 +1055,8 @@ namespace gamescope break; } } - + + // Fraction with denominator of 120 per. spec const uint32_t uScale = oState->uFractionalScale;