From 8a100bf6272bd1d22f2d9f952f9dc115c6dd34e4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 23 Jan 2017 22:48:02 +0100 Subject: [PATCH] issue #0002836: Crash in sketcher --- .../PartDesign/Gui/TaskPrimitiveParameters.cpp | 16 +++++++++++++--- src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index a74e33180..7497dfa44 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -220,7 +220,11 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) if(i != index) ui.widgetStack->widget(i)->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored)); } - + + Gui::Document* doc = vp->getDocument(); + this->attachDocument(doc); + this->enableNotifications(DocumentObserver::Delete); + //show the parts coordinate system axis for selection PartDesign::Body * body = PartDesign::Body::findBodyOf(vp->getObject()); if(body) { @@ -241,8 +245,8 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) TaskBoxPrimitives::~TaskBoxPrimitives() { //hide the parts coordinate system axis for selection - PartDesign::Body * body = PartDesign::Body::findBodyOf ( vp->getObject() ); - if(body) { + PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : 0; + if (body) { try { App::Origin *origin = body->getOrigin(); Gui::ViewProviderOrigin* vpOrigin; @@ -254,6 +258,12 @@ TaskBoxPrimitives::~TaskBoxPrimitives() } } +void TaskBoxPrimitives::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + if (this->vp == &Obj) + this->vp = nullptr; +} + void TaskBoxPrimitives::onBoxHeightChanged(double v) { PartDesign::Box* box = static_cast(vp->getObject()); box->Height.setValue(v); diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h index 4f605ac9b..073a4d445 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h @@ -26,6 +26,7 @@ #include #include +#include #include #include "TaskSketchBasedParameters.h" @@ -49,7 +50,8 @@ namespace PartDesignGui { namespace s = boost::signals; -class TaskBoxPrimitives : public Gui::TaskView::TaskBox +class TaskBoxPrimitives : public Gui::TaskView::TaskBox, + public Gui::DocumentObserver { Q_OBJECT @@ -98,7 +100,11 @@ public Q_SLOTS: void onWedgeX2inChanged(double); void onWedgeZ2maxChanged(double); void onWedgeZ2inChanged(double); - + +private: + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); + private: QWidget* proxy; Ui_DlgPrimitives ui;