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.

(cherry picked from commit 887c8d3bdf)
This commit is contained in:
tetektoza
2026-01-09 07:21:54 +01:00
committed by Max Wilfinger
parent 116bb0dcd2
commit 69c09f6a13
2 changed files with 2 additions and 0 deletions
@@ -1706,6 +1706,7 @@ void TaskSketcherConstraints::slotConstraintsChanged()
assert(sketchView);
constraintMap.clear();
selectionBuffer.clear();
// Build up ListView with the constraints
const Sketcher::SketchObject* sketch = sketchView->getSketchObject();
@@ -1873,6 +1873,7 @@ void TaskSketcherElements::slotElementsChanged()
ui->listWidgetElements->clear();
elementMap.clear();
selectionBuffer.clear();
using GeometryState = ElementItem::GeometryState;