diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 4ab0d311b5..8c0782b420 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -337,17 +337,18 @@ void Body::setBaseProperty(App::DocumentObject* feature) std::vector Body::removeObject(App::DocumentObject* feature) { + // This method must be called BEFORE the feature is removed from the Document! + App::DocumentObject* nextSolidFeature = getNextSolidFeature(feature); App::DocumentObject* prevSolidFeature = getPrevSolidFeature(feature); - // This method must be called BEFORE the feature is removed from the Document! - if (isSolidFeature(feature)) { - // This is a solid feature - // If the next feature is solid, reroute its BaseFeature property to the previous solid feature - if (nextSolidFeature) { - assert(nextSolidFeature->isDerivedFrom(PartDesign::Feature::getClassTypeId())); - // Note: It's ok to remove the first solid feature, that just mean the next feature - // become the base one - static_cast(nextSolidFeature)->BaseFeature.setValue(prevSolidFeature); + + // It's ok to remove the first solid feature, that just mean the next feature become the base one + + if (nextSolidFeature && nextSolidFeature->isDerivedFrom(PartDesign::Feature::getClassTypeId())) { + auto* nextPD = static_cast(nextSolidFeature); + // Check if the next feature is pointing to the one being deleted + if (nextPD->BaseFeature.getValue() == feature) { + nextPD->BaseFeature.setValue(prevSolidFeature); } }