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
This commit is contained in:
Sander Adamson
2025-08-01 09:47:28 +01:00
committed by dpasukhi
parent 045c19b941
commit 5faa86f3e5
2 changed files with 36 additions and 13 deletions

View 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

View File

@@ -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