From 6891615a1306b33f6349582353b12dac0886a287 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 31 Mar 2024 14:30:21 +0800 Subject: [PATCH] Gui: fix crash on contextual pie menu switching workbench Fixes #978 --- src/Gui/Action.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 5f6e34291417..865de04984ae 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -2671,7 +2671,7 @@ class StdCmdToolbarSubMenu : public Gui::Command // -------------------------------------------------------------------- ToolbarMenuAction::ToolbarMenuAction ( Command* pcCmd, QObject * parent ) - : Action(pcCmd, parent), _menu(0) + : Action(pcCmd, parent), _menu(nullptr) , _pimpl(new Private(this, "User parameter:BaseApp/Workbench/Global/Toolbar")) { _pimpl->hShortcut = WindowParameter::getDefaultParameter()->GetGroup("Shortcut"); @@ -2800,8 +2800,16 @@ void ToolbarMenuAction::update() void ToolbarMenuAction::popup(const QPoint &pt) { + _menu->setActiveAction(nullptr); PieMenu::exec(_menu, pt, command()->getName()); - _menu->setActiveAction(0); + + // WARNING! In some case, this ToolbarMenuAction instance may have been + // destroyed after returning from PieMenu::exec(). E.g. when the toolbar + // menu is a PartDesign context menu/command, and the action triggers + // switching to Sketcher workbench, causing all PartDesign context commands + // being destroyed. So, must not access any member here. + // + // _menu->setActiveAction(nullptr); } ////////////////////////////////////////////////////////////////////