From 3b1c433daaf99193087c3999761fcb620f4e7340 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 29 Sep 2017 21:22:48 +0200 Subject: [PATCH] fix crashes when aborting linear pattern panel due access of null pointers --- src/Mod/PartDesign/Gui/ReferenceSelection.cpp | 3 +++ .../Gui/TaskLinearPatternParameters.cpp | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index 18f469346a..1ec8d1431e 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -196,6 +196,9 @@ namespace PartDesignGui void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::SelectionChanges& msg, App::DocumentObject*& selObj, std::vector& selSub) { + if (!thisObj) + return; + if (strcmp(thisObj->getDocument()->getName(), msg.pDocName) != 0) return; diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 8d0f1ac49d..338b3ca3d7 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -248,15 +248,19 @@ void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges // TODO check if this works correctly (2015-09-01, Fat-Zer) exitSelectionMode(); std::vector directions; - App::DocumentObject* selObj; + App::DocumentObject* selObj = nullptr; PartDesign::LinearPattern* pcLinearPattern = static_cast(getObject()); - getReferencedSelection(pcLinearPattern, msg, selObj, directions); - // Note: ReferenceSelection has already checked the selection for validity - if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) { - pcLinearPattern->Direction.setValue(selObj, directions); + if (pcLinearPattern) { + getReferencedSelection(pcLinearPattern, msg, selObj, directions); - recomputeFeature(); - updateUI(); + // Note: ReferenceSelection has already checked the selection for validity + if (selObj && (selectionMode == reference || + selObj->isDerivedFrom(App::Line::getClassTypeId()))) { + pcLinearPattern->Direction.setValue(selObj, directions); + + recomputeFeature(); + updateUI(); + } } } }