]> OCCT Git - occt.git/commitdiff
Modeling - Fix null surface crash in UnifySameDomain (#624)
authorSander Adamson <sander.adamson@cloudnc.com>
Fri, 1 Aug 2025 08:47:28 +0000 (09:47 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Aug 2025 08:47:28 +0000 (09:47 +0100)
- 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

src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx
tests/bugs/modalg_8/bug33894 [new file with mode: 0644]

index a4c9760d3bfba51dc21d356f4687b17f1e2293ce..ed1c55d1f5ad70a6a0f8b05b4929c70f14567414 100644 (file)
@@ -56,6 +56,7 @@
 #include <ShapeFix_Face.hxx>
 #include <ShapeFix_Shell.hxx>
 #include <ShapeFix_Wire.hxx>
+#include <Standard_NullValue.hxx>
 #include <Standard_Type.hxx>
 #include <TColGeom2d_Array1OfBSplineCurve.hxx>
 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
@@ -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 (file)
index 0000000..21f3cb1
--- /dev/null
@@ -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