Skip to content

Sketcher: Fix crash when applying constraints during selection batching#26741

Merged
chennes merged 1 commit intoFreeCAD:mainfrom
tetektoza:fix/26734_fix_crash_when_applying_tangent_constraint
Jan 8, 2026
Merged

Sketcher: Fix crash when applying constraints during selection batching#26741
chennes merged 1 commit intoFreeCAD:mainfrom
tetektoza:fix/26734_fix_crash_when_applying_tangent_constraint

Conversation

@tetektoza
Copy link
Member

@tetektoza tetektoza commented Jan 7, 2026

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.

Would you be able to check @PaddleStroke?

Demo: nothing to show, was crashing, doesn't crash now. At least on my Debian machine.

Resolves: #26734

Currently, the selection batching optimization introduced in FreeCAD#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.
@maxwxyz maxwxyz added this to the 1.1 milestone Jan 7, 2026
@maxwxyz maxwxyz added Type: Bug This issue or PR is related to a bug backport releases/FreeCAD-1-1 Applied to a PR that is on main to trigger the automatic creation of another PR onto 1.1 labels Jan 7, 2026
@maxwxyz maxwxyz moved this from Queue to Merge Meeting in Merge Queue Jan 7, 2026
@PaddleStroke
Copy link
Contributor

Thanks for the catch @tetektoza !
Sorry for the regression

@github-actions github-actions bot added the Mod: Sketcher Related to the Sketcher Workbench label Jan 7, 2026
@chennes chennes merged commit 887c8d3 into FreeCAD:main Jan 8, 2026
16 checks passed
@github-project-automation github-project-automation bot moved this from Merge Meeting to Done in Merge Queue Jan 8, 2026
@freecad-ci-runner
Copy link
Collaborator

Successfully created backport PR for releases/FreeCAD-1-1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport releases/FreeCAD-1-1 Applied to a PR that is on main to trigger the automatic creation of another PR onto 1.1 Mod: Sketcher Related to the Sketcher Workbench Type: Bug This issue or PR is related to a bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Crash when applying tangent constraint

5 participants