From be1622176c7376a92eae9b866d7ad4247bdf69ab Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 19 Nov 2024 12:14:03 +0100 Subject: [PATCH] Core: Fix dangling pointer in SoFCUnifiedSelection::setSelection This fixes #17965: Measurement: Crash when clicking on COM label --- src/Gui/SoFCUnifiedSelection.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index 79d97c20d7..719e384139 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -79,6 +79,7 @@ #include "SoFCUnifiedSelection.h" #include "Application.h" #include "Document.h" +#include "DocumentObserver.h" #include "MainWindow.h" #include "SoFCInteractiveElement.h" #include "SoFCSelectionAction.h" @@ -607,9 +608,16 @@ bool SoFCUnifiedSelection::setSelection(const std::vector &infos, bo return true; } else { + // Changing the selection may result in destroying this view provider. + // So, make sure that the object still exists afterwards (#17965) + ViewProviderWeakPtrT guard(vpd); getFullSubElementName(subName); bool ok = Gui::Selection().addSelection(docname, objname, subName.c_str(), pt[0], pt[1], pt[2], &sels); + if (guard.expired()) { + return false; + } + if (ok && mymode == OFF) { snprintf(buf, 512, "Selected: %s.%s.%s (%g, %g, %g)", docname, objname, info.element.c_str(), fabs(pt[0]) > 1e-7 ? pt[0] : 0.0,