From 16aff105443d2dde78da3eeeed087f6bf8a8350c Mon Sep 17 00:00:00 2001 From: pjcreath Date: Thu, 20 Nov 2025 15:22:20 -0500 Subject: [PATCH] Sketcher: prevent crash on undo/redo while dragging. Fixes #25500 --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index faa1c21330..a987921e41 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -653,6 +653,14 @@ ViewProviderSketch::~ViewProviderSketch() void ViewProviderSketch::slotUndoDocument(const Gui::Document& /*doc*/) { + // If undo is triggered during a drag operation, the drag must be canceled to avoid using + // stale geometry IDs, which would lead to a crash. + if (!drag.Dragged.empty() || !drag.DragConstraintSet.empty()) { + drag.reset(); + setSketchMode(STATUS_NONE); + resetPositionText(); + } + // Note 1: this slot is only operative during edit mode (see signal connection/disconnection) // Note 2: ViewProviderSketch::UpdateData does not generate updates during undo/redo // transactions as mid-transaction data may not be in a valid state (e.g. constraints @@ -664,6 +672,14 @@ void ViewProviderSketch::slotUndoDocument(const Gui::Document& /*doc*/) void ViewProviderSketch::slotRedoDocument(const Gui::Document& /*doc*/) { + // If redo is triggered during a drag operation, the drag must be canceled to avoid using + // stale geometry IDs, which would lead to a crash. + if (!drag.Dragged.empty() || !drag.DragConstraintSet.empty()) { + drag.reset(); + setSketchMode(STATUS_NONE); + resetPositionText(); + } + // Note 1: this slot is only operative during edit mode (see signal connection/disconnection) // Note 2: ViewProviderSketch::UpdateData does not generate updates during undo/redo // transactions as mid-transaction data may not be in a valid state (e.g. constraints