From af33cdabe53679bdca74887df2655b4266217c5f Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 23 Dec 2022 11:56:00 +0100 Subject: [PATCH] Surface: fix crash when canceling filling dialog --- src/Mod/Surface/Gui/TaskFilling.cpp | 23 +++++++++++++---------- src/Mod/Surface/Gui/TaskFilling.h | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Mod/Surface/Gui/TaskFilling.cpp b/src/Mod/Surface/Gui/TaskFilling.cpp index b03cd2f001..090a52e4a4 100644 --- a/src/Mod/Surface/Gui/TaskFilling.cpp +++ b/src/Mod/Surface/Gui/TaskFilling.cpp @@ -256,6 +256,7 @@ private: // ---------------------------------------------------------------------------- FillingPanel::FillingPanel(ViewProviderFilling* vp, Surface::Filling* obj) + : editedObject(obj) { ui = new Ui_TaskFilling(); ui->setupUi(this); @@ -462,14 +463,16 @@ bool FillingPanel::accept() bool FillingPanel::reject() { - this->vp->highlightReferences(ViewProviderFilling::Edge, - editedObject->BoundaryEdges.getSubListValues(), false); + if (!editedObject.expired()) { + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); - // unhighlight the referenced face - std::vector links; - links.emplace_back(editedObject->InitialFace.getValue(), - editedObject->InitialFace.getSubValues()); - this->vp->highlightReferences(ViewProviderFilling::Face, links, false); + // unhighlight the referenced face + std::vector links; + links.emplace_back(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues()); + this->vp->highlightReferences(ViewProviderFilling::Face, links, false); + } selectionMode = None; Gui::Selection().rmvSelectionGate(); @@ -496,7 +499,7 @@ void FillingPanel::on_lineInitFaceName_textChanged(const QString& text) void FillingPanel::on_buttonInitFace_clicked() { // 'selectionMode' is passed by reference and changed when the filter is deleted - Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject)); + Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject.get())); selectionMode = InitFace; } @@ -504,7 +507,7 @@ void FillingPanel::on_buttonEdgeAdd_toggled(bool checked) { if (checked) { // 'selectionMode' is passed by reference and changed when the filter is deleted - Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject)); + Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject.get())); selectionMode = AppendEdge; } else if (selectionMode == AppendEdge) { @@ -516,7 +519,7 @@ void FillingPanel::on_buttonEdgeRemove_toggled(bool checked) { if (checked) { // 'selectionMode' is passed by reference and changed when the filter is deleted - Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject)); + Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject.get())); selectionMode = RemoveEdge; } else if (selectionMode == RemoveEdge) { diff --git a/src/Mod/Surface/Gui/TaskFilling.h b/src/Mod/Surface/Gui/TaskFilling.h index d3768f9137..04577f5e70 100644 --- a/src/Mod/Surface/Gui/TaskFilling.h +++ b/src/Mod/Surface/Gui/TaskFilling.h @@ -23,6 +23,7 @@ #ifndef SURFACEGUI_TASKFILLING_H #define SURFACEGUI_TASKFILLING_H +#include #include #include #include @@ -74,7 +75,7 @@ protected: RemoveEdge = SurfaceGui::SelectionMode::RemoveEdge }; SelectionMode selectionMode; - Surface::Filling* editedObject; + App::WeakPtrT editedObject; bool checkCommand; private: