algo/scroll: fix std::clamp assertion crash on resume from suspend (#13737)

This commit is contained in:
Nathan Ollerenshaw 2026-03-15 08:06:10 -07:00 committed by GitHub
parent 9bf8fe7a52
commit df55752241
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -240,7 +240,17 @@ void CScrollTapeController::fitStrip(size_t stripIndex, const CBox& usableArea,
const double stripStart = calculateStripStart(stripIndex, usableArea, fullscreenOnOne);
const double stripSize = calculateStripSize(stripIndex, usableArea, fullscreenOnOne);
m_offset = std::clamp(m_offset, stripStart - usablePrimary + stripSize, stripStart);
const double lo = stripStart - usablePrimary + stripSize;
const double hi = stripStart;
if (lo > hi) {
// strip is wider than viewport (e.g. during monitor reconnection after suspend),
// center the strip instead of hitting the std::clamp assertion
m_offset = stripStart - (usablePrimary - stripSize) / 2.0;
return;
}
m_offset = std::clamp(m_offset, lo, hi);
}
bool CScrollTapeController::isStripVisible(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne, bool full) const {

View file

@ -795,6 +795,11 @@ void CScrollingAlgorithm::resizeTarget(const Vector2D& delta, SP<ITarget> target
}
void CScrollingAlgorithm::recalculate() {
// guard against recalculation during transitional monitor states
// (e.g. monitor reconnecting after suspend where workspace/monitor may not be ready)
if (!m_parent || !m_parent->space() || !m_parent->space()->workspace() || !m_parent->space()->workspace()->m_monitor)
return;
if (Desktop::focusState()->window()) {
const auto TARGET = Desktop::focusState()->window()->layoutTarget();
@ -1516,6 +1521,12 @@ CBox CScrollingAlgorithm::usableArea() {
return box;
box.translate(-m_parent->space()->workspace()->m_monitor->m_position);
// ensure dimensions are never zero or negative, which can happen during
// monitor transitions (e.g. reconnection after suspend with stale reserved areas)
box.w = std::max(box.w, 1.0);
box.h = std::max(box.h, 1.0);
return box;
}