]> OCCT Git - occt.git/commitdiff
Modelling - ShapeUpgrade_UnifySameDomain crash (#876)
authorDmitrii Kulikov <164657232+AtheneNoctuaPt@users.noreply.github.com>
Thu, 4 Dec 2025 19:03:00 +0000 (19:03 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Fri, 5 Dec 2025 22:48:11 +0000 (22:48 +0000)
- Added null safety checks for `BRepAdaptor_Curve2d::Curve()` before evaluating curve parameters
- Modernized variable declarations with `const` qualifiers
- Replaced conditional assignment with `std::min` for cleaner code

src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx

index ed1c55d1f5ad70a6a0f8b05b4929c70f14567414..a43cbfb727cde9693b83ba06e74d5dbb1037cbca 100644 (file)
@@ -332,9 +332,14 @@ static Standard_Real ComputeMinEdgeSize(const TopTools_SequenceOfShape& theEdges
     TopoDS_Vertex V1, V2;
     TopExp::Vertices(anEdge, V1, V2);
     BRepAdaptor_Curve2d BAcurve2d(anEdge, theRefFace);
-    gp_Pnt2d            FirstP2d = BAcurve2d.Value(BAcurve2d.FirstParameter());
-    gp_Pnt2d            LastP2d  = BAcurve2d.Value(BAcurve2d.LastParameter());
-    Standard_Real       aSqDist;
+    if (BAcurve2d.Curve().IsNull())
+    {
+      continue;
+    }
+
+    const gp_Pnt2d FirstP2d = BAcurve2d.Value(BAcurve2d.FirstParameter());
+    const gp_Pnt2d LastP2d  = BAcurve2d.Value(BAcurve2d.LastParameter());
+    Standard_Real  aSqDist;
     if (V1.IsSame(V2) && !BRep_Tool::Degenerated(anEdge))
     {
       gp_Pnt2d MidP2d =
@@ -342,9 +347,11 @@ static Standard_Real ComputeMinEdgeSize(const TopTools_SequenceOfShape& theEdges
       aSqDist = FirstP2d.SquareDistance(MidP2d);
     }
     else
+    {
       aSqDist = FirstP2d.SquareDistance(LastP2d);
-    if (aSqDist < MinSize)
-      MinSize = aSqDist;
+    }
+
+    MinSize = std::min(MinSize, aSqDist);
   }
   MinSize = Sqrt(MinSize);
   return MinSize;
@@ -3568,8 +3575,13 @@ void ShapeUpgrade_UnifySameDomain::IntUnifyFaces(
       {
         const TopoDS_Edge&  anEdge = TopoDS::Edge(edges(ii));
         BRepAdaptor_Curve2d aBAcurve(anEdge, F_RefFace);
-        gp_Pnt2d            aFirstPoint = aBAcurve.Value(aBAcurve.FirstParameter());
-        gp_Pnt2d            aLastPoint  = aBAcurve.Value(aBAcurve.LastParameter());
+        if (aBAcurve.Curve().IsNull())
+        {
+          continue;
+        }
+
+        gp_Pnt2d aFirstPoint = aBAcurve.Value(aBAcurve.FirstParameter());
+        gp_Pnt2d aLastPoint  = aBAcurve.Value(aBAcurve.LastParameter());
 
         if (aFirstPoint.X() < FaceUmin)
           FaceUmin = aFirstPoint.X();
@@ -3604,6 +3616,11 @@ void ShapeUpgrade_UnifySameDomain::IntUnifyFaces(
         Standard_Real        fpar, lpar;
         Handle(Geom2d_Curve) StartPCurve =
           BRep_Tool::CurveOnSurface(StartEdge, F_RefFace, fpar, lpar);
+        if (StartPCurve.IsNull())
+        {
+          edges.Remove(istart);
+          continue;
+        }
         TopoDS_Vertex StartVertex, CurVertex;
         TopExp::Vertices(StartEdge, StartVertex, CurVertex, Standard_True); // with orientation
         Standard_Real StartParam, CurParam;