From: Sander Adamson Date: Fri, 1 Aug 2025 08:47:28 +0000 (+0100) Subject: Modeling - Fix null surface crash in UnifySameDomain (#624) X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=65742e7375ff71a022eda677778a25b6bb14650a;p=occt.git Modeling - Fix null surface crash in UnifySameDomain (#624) - Added null safety checks in the ClearRts function and IntUnifyFaces method - Refactored ClearRts to use a more concise implementation with null handling - Added a test case to verify the fix works with tessellated geometry --- diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx index a4c9760d3b..ed1c55d1f5 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -1325,13 +1326,9 @@ static Standard_Boolean getCylinder(Handle(Geom_Surface)& theInSurface, gp_Cylin static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface) { - if (aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) - { - Handle(Geom_RectangularTrimmedSurface) rts = - Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); - return rts->BasisSurface(); - } - return aSurface; + const Handle(Geom_RectangularTrimmedSurface) aRTS = + Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); + return aRTS.IsNull() ? aSurface : aRTS->BasisSurface(); } //======================================================================= @@ -3007,11 +3004,18 @@ void ShapeUpgrade_UnifySameDomain::IntUnifyFaces( TopExp_Explorer exp; for (exp.Init(theInpShape, TopAbs_FACE); exp.More(); exp.Next()) { - - TopoDS_Face aFace = TopoDS::Face(exp.Current()); - + const TopoDS_Face aFace = TopoDS::Face(exp.Current()); if (aProcessed.Contains(aFace)) + { continue; + } + + const Handle(Geom_Surface) aBaseSurface = ClearRts(BRep_Tool::Surface(aFace)); + // Bug 33894: Prevent crash when face has no surface + if (aBaseSurface.IsNull()) + { + continue; + } // Boundary edges for the new face TopTools_SequenceOfShape edges; @@ -3027,9 +3031,7 @@ void ShapeUpgrade_UnifySameDomain::IntUnifyFaces( faces.Append(aFace); // surface and location to construct result - TopLoc_Location aBaseLocation; - Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace); - aBaseSurface = ClearRts(aBaseSurface); + TopLoc_Location aBaseLocation; TopAbs_Orientation RefFaceOrientation = aFace.Orientation(); // Take original surface diff --git a/tests/bugs/modalg_8/bug33894 b/tests/bugs/modalg_8/bug33894 new file mode 100644 index 0000000000..21f3cb1bc7 --- /dev/null +++ b/tests/bugs/modalg_8/bug33894 @@ -0,0 +1,21 @@ +puts "========================================================================" +puts "Bug 33894: unifysamedom crashes on tessellated geometry without surfaces" +puts "No crash expected" +puts "========================================================================" + +pload XDE MODELING + +stepread [locate_data_file gh624_tessellated_tetrahedron_ap242.step] anInputShape * + +# Check what kind of shape we get +checknbshapes anInputShape_1 -t + +# Validate shape - will show BRepCheck_NoSurface errors +puts "REQUIRED All: Faulty shapes in variables faulty_1 to faulty_6" +checkshape anInputShape_1 + +# Unify shapes. No crash expected. +unifysamedom aUnified anInputShape_1 + +# Check result. +checknbshapes aUnified -face 4 -shell 1 -solid 1 -shape 6 -t