From 897fcdaa991f16b4160b5a5ed32f41c8f317824d Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 4 Jun 2026 11:37:10 +1000 Subject: [PATCH] wayland/lock: avoid creating lock surfaces for uninited wl screens --- changelog/next.md | 1 + src/wayland/session_lock.cpp | 8 ++++++-- src/wayland/session_lock/surface.cpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/changelog/next.md b/changelog/next.md index 4c689f76..72271e8a 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -4,3 +4,4 @@ - Fixed WlSessionLockSurface.visible crashing if accessed before backing surface creation. - Fixed mpris players returning `rate` for `minRate` and `maxRate`. - Fixed missing/wrong change signals on various properties. +- Fixed session lock crashes on sleep, wake, DPMS, and unlocking. diff --git a/src/wayland/session_lock.cpp b/src/wayland/session_lock.cpp index 3b908b8e..1ae8d2ea 100644 --- a/src/wayland/session_lock.cpp +++ b/src/wayland/session_lock.cpp @@ -56,9 +56,12 @@ void WlSessionLock::updateSurfaces(bool show, WlSessionLock* old) { auto screens = QGuiApplication::screens(); screens.removeIf([](QScreen* screen) { - if (dynamic_cast(screen->handle()) == nullptr) { + auto* waylandScreen = dynamic_cast(screen->handle()); + if (waylandScreen == nullptr || waylandScreen->isPlaceholder() + || waylandScreen->output() == nullptr) + { qDebug() << "Not creating lock surface for screen" << screen - << "as it is not backed by a wayland screen."; + << "as it is not backed by a valid wayland output."; return true; } @@ -207,6 +210,7 @@ WlSessionLockSurface::WlSessionLockSurface(QObject* parent) WlSessionLockSurface::~WlSessionLockSurface() { if (this->window != nullptr) { + this->window->destroy(); this->window->deleteLater(); } } diff --git a/src/wayland/session_lock/surface.cpp b/src/wayland/session_lock/surface.cpp index d42c7f0f..b8644c0b 100644 --- a/src/wayland/session_lock/surface.cpp +++ b/src/wayland/session_lock/surface.cpp @@ -38,6 +38,7 @@ QSWaylandSessionLockSurface::QSWaylandSessionLockSurface(QtWaylandClient::QWayla } QSWaylandSessionLockSurface::~QSWaylandSessionLockSurface() { + if (this->object() == nullptr) return; if (this->ext != nullptr) this->ext->surface = nullptr; this->destroy(); }