From cc7384180b158b1b23e916f0281d0ec0c5785850 Mon Sep 17 00:00:00 2001 From: zorowk Date: Wed, 27 May 2026 16:17:01 +0800 Subject: [PATCH] fix(dockpreview): drop invalidated wrappers from preview Remove dock preview entries when their SurfaceWrapper becomes invalidated to avoid reading deleted objects in QML. Log: Remove invalidated dock preview wrappers PMS: BUG-363155 1162 Influence: Prevent dock preview crashes from stale SurfaceWrapper references. --- src/core/qml/DockPreview.qml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/qml/DockPreview.qml b/src/core/qml/DockPreview.qml index a787fffafc..629278174a 100644 --- a/src/core/qml/DockPreview.qml +++ b/src/core/qml/DockPreview.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd. // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only import QtQuick @@ -76,6 +76,18 @@ Item { } } + function removeSurface(surfaceWrapper) { + if (!surfaceWrapper) + return; + + var index = desiredSurfaces.indexOf(surfaceWrapper); + if (index < 0) + return; + + desiredSurfaces.splice(index, 1); + updateModel(); + } + function activateWindow(surfaceWrapper) { console.debug(qLcDockPreview, "activate preview window: ", surfaceWrapper) Helper.forceActivateSurface(surfaceWrapper) @@ -471,6 +483,13 @@ Item { implicitHeight: root.isHorizontal ? 120 : Math.max(80, Math.min(120, 240 * wrapper.height / wrapper.width)) implicitWidth: root.isHorizontal ? Math.max(80, Math.min(240, 120 * wrapper.width / wrapper.height)) : 240 + Connections { + target: wrapper + function onAboutToBeInvalidated() { + listview.model.removeSurface(wrapper) + } + } + ListView.onRemove: { if (filterSurfaceModel.count) { isRemoving = true