From aff34089c4d66b951d25a0dc1867f7fb93d61a7d Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 1 Jan 2025 13:47:16 +0100 Subject: [PATCH] monitor: avoid crashes on no good modes fixes #8915 --- src/helpers/Monitor.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 01bb79ac..76df00b3 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -480,10 +480,12 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) { }); // if the best mode isnt close to requested, then try requested as custom mode first - auto bestMode = requestedModes.back(); - if (!DELTALESSTHAN(bestMode->pixelSize.x, RULE->resolution.x, 1) || !DELTALESSTHAN(bestMode->pixelSize.y, RULE->resolution.y, 1) || - !DELTALESSTHAN(bestMode->refreshRate / 1000.f, RULE->refreshRate, 1)) - requestedModes.push_back(makeShared(Aquamarine::SOutputMode{.pixelSize = RULE->resolution, .refreshRate = RULE->refreshRate * 1000.f})); + if (!requestedModes.empty()) { + auto bestMode = requestedModes.back(); + if (!DELTALESSTHAN(bestMode->pixelSize.x, RULE->resolution.x, 1) || !DELTALESSTHAN(bestMode->pixelSize.y, RULE->resolution.y, 1) || + !DELTALESSTHAN(bestMode->refreshRate / 1000.f, RULE->refreshRate, 1)) + requestedModes.push_back(makeShared(Aquamarine::SOutputMode{.pixelSize = RULE->resolution, .refreshRate = RULE->refreshRate * 1000.f})); + } // then if requested is custom, try custom mode first if (RULE->drmMode.type == DRM_MODE_TYPE_USERDEF) { @@ -510,8 +512,12 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) { if (Debug::trace) { Debug::log(TRACE, "Monitor {} requested modes:", szName); - for (auto const& mode : requestedModes | std::views::reverse) { - Debug::log(TRACE, "| {:X0}@{:.2f}Hz", mode->pixelSize, mode->refreshRate / 1000.f); + if (requestedModes.empty()) + Debug::log(TRACE, "| None"); + else { + for (auto const& mode : requestedModes | std::views::reverse) { + Debug::log(TRACE, "| {:X0}@{:.2f}Hz", mode->pixelSize, mode->refreshRate / 1000.f); + } } }