Sketcher: Fix segfault when activating a tool in a different view

=================================================================

When in Sketcher edit mode, a tool button is activated, while the view has been changing to view of a different type, it segfaults.

This commit checks the pointer of the view to ensure correct type before activation, and refusing to activate if not of the correct type.

fixes #10809
This commit is contained in:
Abdullah Tahiri
2023-10-01 08:48:08 +02:00
committed by abdullahtahiriyo
parent 2ea27064d5
commit c7b99b9fbb
2 changed files with 19 additions and 10 deletions

View File

@@ -283,14 +283,20 @@ void DrawSketchHandler::activate(ViewProviderSketch* vp)
sketchgui = vp;
// save the cursor at the time the DSH is activated
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
oldCursor = viewer->getWidget()->cursor();
auto* view = dynamic_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow());
updateCursor();
if (view) {
Gui::View3DInventorViewer* viewer = dynamic_cast<Gui::View3DInventor*>(view)->getViewer();
oldCursor = viewer->getWidget()->cursor();
this->preActivated();
this->activated();
updateCursor();
this->preActivated();
this->activated();
}
else {
sketchgui->purgeHandler();
}
}
void DrawSketchHandler::deactivate()