Fuzzy boolean operations give access violation under certain circumstances

Occurs in OCCT 7.4.0. Respective Code is unchanged in OCCT 7.6.0:

happens if myUparams.IsNull() in

void IntTools_SurfaceRangeLocalizeData::SetFrame(const Standard_Real theUMin,
                         const Standard_Real theUMax,
                         const Standard_Real theVMin,
                         const Standard_Real theVMax)
{
  myUIndMin   = 0;
  myUIndMax   = 0;
  myVIndMin   = 0;
  myVIndMax   = 0;

  if (myUParams.IsNull() || myVParams.IsNull()) {
    return;
  }

The routine is used in

IntTools\IntTools_BeanFaceIntersector.cxx

void BuildBox(const Handle(Geom_BSplineSurface)       &theSurf,
      const Standard_Real                      theFirstU,
      const Standard_Real                      theLastU,
      const Standard_Real                      theFirstV,
      const Standard_Real                      theLastV,
            IntTools_SurfaceRangeLocalizeData &theSurfaceData,
              Bnd_Box                           &theBox)
{
  Standard_Integer i;
  Standard_Integer j;
  Standard_Integer aNbUPnts;
  Standard_Integer aNbVPnts;
  Standard_Real    aParam;
  gp_Pnt           aPnt;

  theSurfaceData.SetFrame(theFirstU, theLastU, theFirstV, theLastV);
  aNbUPnts = theSurfaceData.GetNBUPointsInFrame();
  aNbVPnts = theSurfaceData.GetNBVPointsInFrame();

  // Add corner points.
  theSurf->D0(theFirstU, theFirstV, aPnt);
  theBox.Add(aPnt);
  theSurf->D0(theLastU,  theFirstV, aPnt);
  theBox.Add(aPnt);
  theSurf->D0(theFirstU, theLastV, aPnt);
  theBox.Add(aPnt);
  theSurf->D0(theLastU,  theLastV, aPnt);
  theBox.Add(aPnt);

  for (i = 1; i <= aNbUPnts; i++) {
    // Add top and bottom points.
    aParam = theSurfaceData.GetUParamInFrame(i);

and the access violation occurs then in GetUParamInFrame(i), because e.g. aNbUPnts = 1, because:

inline Standard_Integer IntTools_SurfaceRangeLocalizeData::
                                 GetNBUPointsInFrame() const
{
  return myUIndMax - myUIndMin + 1;
}

0-0+1 = 1

Mikhail Sazonov's picture

You are welcome to report a bug in the bugtracker. It is highly needed to provide the model to reproduce the bug.

Christoph Jung's picture

Unfortunately, I do not know how to use the bugtracker, or how to get access. Therefore, please find the model in the new comment

Mikhail Sazonov's picture

https://tracker.dev.opencascade.org/my_view_page.php

Just report new issue, filling in all necessary fields.

Christoph Jung's picture

This would be a model to reproduce the bug:

TopoDS_Shape s;
BRep_Builder b;
std::ifstream is;
is.open("D://EF.brep");
BRepTools::Read(s, is, b);
is.close();
TopExp_Explorer exp(s, TopAbs_FACE);
TopExp_Explorer expe(s, TopAbs_EDGE);
IntTools_EdgeFace* in = new IntTools_EdgeFace();
in->SetEdge(TopoDS::Edge(expe.Current()));
in->SetFuzzyValue(0.1);
in->SetFace(TopoDS::Face(exp.Current()));
in->UseQuickCoincidenceCheck(false);
in->SetRange(5.1673518776073308, 6.7381478044021721);
in->Perform();

Attachments: 
Christoph Jung's picture

It gives an access violation, if you debug it with MS VS 2019.