diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index 913483341d..918c3eb2eb 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -143,9 +143,16 @@ bool ViewProvider::setEdit(int ModNum) } } - previouslyShownViewProvider = dynamic_cast( - Gui::Application::Instance->getViewProvider(getBodyViewProvider()->getShownFeature()) - ); + // This is handling for an erroneous case where features are for some reason placed outside + // the body container. That should never happen, but in some cases we find models with a + // problem like that. + if (ViewProviderBody* bodyViewProvider = getBodyViewProvider()) { + PartDesign::Feature* shownFeature = bodyViewProvider->getShownFeature(); + + previouslyShownViewProvider = freecad_cast( + Gui::Application::Instance->getViewProvider(shownFeature) + ); + } // clear the selection (convenience) Gui::Selection().clearSelection();