From 55cdfefce1f6fb635ad4f2f5f2746e41bf10e093 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 19 Feb 2021 11:33:58 +0100 Subject: [PATCH] PD: [skip ci] recompute document when canceling task dialog, fix also possible crash --- src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp index 37e6cb2f4d..e015a90b20 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp @@ -26,6 +26,7 @@ #include #endif +#include #include #include #include @@ -143,6 +144,8 @@ bool TaskDlgFeatureParameters::accept() { bool TaskDlgFeatureParameters::reject() { PartDesign::Feature* feature = static_cast(vp->getObject()); + App::DocumentObjectWeakPtrT weakptr(feature); + App::Document* document = feature->getDocument(); PartDesign::Body* body = PartDesign::Body::findBodyOf(feature); @@ -159,17 +162,17 @@ bool TaskDlgFeatureParameters::reject() param->detachSelection(); } - // roll back the done things + // roll back the done things which may delete the feature Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); // if abort command deleted the object make the previous feature visible again - if (!Gui::Application::Instance->getViewProvider(feature)) { + if (weakptr.expired()) { // Make the tip or the previous feature visible again with preference to the previous one // TODO: ViewProvider::onDelete has the same code. May be this one is excess? if (previous && Gui::Application::Instance->getViewProvider(previous)) { Gui::Application::Instance->getViewProvider(previous)->show(); - } else if (body != NULL) { + } + else if (body) { App::DocumentObject* tip = body->Tip.getValue(); if (tip && Gui::Application::Instance->getViewProvider(tip)) { Gui::Application::Instance->getViewProvider(tip)->show(); @@ -177,6 +180,9 @@ bool TaskDlgFeatureParameters::reject() } } + Gui::cmdAppDocument(document, "recompute()"); + Gui::cmdGuiDocument(document, "resetEdit()"); + return true; }