From 887c8d3bdf55e05d4ff8fed6e3b56321fd4cc6b9 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Wed, 7 Jan 2026 20:59:02 +0100 Subject: [PATCH] Sketcher: Fix crash when applying constraints during selection batching Currently, the selection batching optimization introduced in #26663 stores ElementItem/ConstraintItem pointers in a buffer to be processed on the next event loop cycle via `QTimer::singleShot`. When a constraint is applied, `slotElementsChanged()/slotConstraintsChanged()` rebuilds the list widget, destroying all items. However, the selection buffer was not cleared, leaving dangling pointers. When `processSelectionBuffer()` executed, it attempted to call `QListWidget::row()` on deleted items, causing a segmentation fault. So, this patch fixes it by clearing `selectionBuffer` when the list is rebuilt, since the buffered pointers are invalidated anyway. --- src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp | 1 + src/Mod/Sketcher/Gui/TaskSketcherElements.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp index caa6c178c6..2fa922bcfc 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp @@ -1708,6 +1708,7 @@ void TaskSketcherConstraints::slotConstraintsChanged() assert(sketchView); constraintMap.clear(); + selectionBuffer.clear(); // Build up ListView with the constraints const Sketcher::SketchObject* sketch = sketchView->getSketchObject(); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 98d5cefe6d..095c67b632 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -1875,6 +1875,7 @@ void TaskSketcherElements::slotElementsChanged() ui->listWidgetElements->clear(); elementMap.clear(); + selectionBuffer.clear(); using GeometryState = ElementItem::GeometryState;