Skip to content

Commit

Permalink
Sketcher: Fix segfault when activating a tool in a different view
Browse files Browse the repository at this point in the history
=================================================================

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 FreeCAD#10809
  • Loading branch information
abdullahtahiriyo committed Oct 7, 2023
1 parent 37b68f3 commit 96efff8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/Mod/Sketcher/Gui/DrawSketchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

if (view) {
Gui::View3DInventorViewer* viewer = dynamic_cast<Gui::View3DInventor*>(view)->getViewer();
oldCursor = viewer->getWidget()->cursor();

updateCursor();
updateCursor();

this->preActivated();
this->activated();
this->preActivated();
this->activated();
}
else {
sketchgui->purgeHandler();
}
}

void DrawSketchHandler::deactivate()
Expand Down
11 changes: 7 additions & 4 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,13 @@ void ViewProviderSketch::purgeHandler()
Gui::Selection().clearSelection();

// ensure that we are in sketch only selection mode
Gui::MDIView* mdi = Gui::Application::Instance->editDocument()->getActiveView();
Gui::View3DInventorViewer* viewer;
viewer = static_cast<Gui::View3DInventor*>(mdi)->getViewer();
viewer->setSelectionEnabled(false);
auto* view = dynamic_cast<Gui::View3DInventor*>(Gui::Application::Instance->editDocument()->getActiveView());

if(view) {
Gui::View3DInventorViewer* viewer;
viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
viewer->setSelectionEnabled(false);
}
}

void ViewProviderSketch::setAxisPickStyle(bool on)
Expand Down

0 comments on commit 96efff8

Please sign in to comment.