IncrementalMesh crash with Common generated surface.

I have two boxes touching at a part of the boundary. I can compute the intersection (BRepAlgoAPI_Common) but when I try to mesh the surface I get a crash. Perhaps some sees what I am doing wrong? Does the intersection perhaps return both intersecting faces from both boxed and I need to merge them somehow? Thanks.

Here is the code to reproduce the issue:

---------------------
#include
#include
#include
#include

int main()
{
gp_Pnt gp1 = gp_Pnt(0,0,0);
gp_Pnt gp2 = gp_Pnt(1,1,1);
gp_Pnt gp3 = gp_Pnt(1,0.5,0.5);
gp_Pnt gp4 = gp_Pnt(2,1.5,1.5);
TopoDS_Shape s1 = BRepPrimAPI_MakeBox(gp1, gp2).Shape();
TopoDS_Shape s2 = BRepPrimAPI_MakeBox(gp3, gp4).Shape();
TopoDS_Shape shape = BRepAlgoAPI_Common(s1, s2).Shape();
BRepMesh_IncrementalMesh Mesh( shape, 0.01 );
Mesh.Perform();
return 0;
}

Thomas Anderson's picture

FYI: This is not crashing for me. occ v7.4.* (8bfae263c1) debian buster.

Oliver R's picture

Thanks Thomas for checking this, good to know that it is no longer crashing.

Eugeny's picture

Documentation for Boolean Operations algorithm says:

The result of the operation Common for arguments S1 and S2 is defined for all values of the dimensions of the arguments. The result can contain shapes of different dimensions, but the minimal dimension of the result will be equal to the minimal dimension of the arguments. For example, the result of the operation Common between edges cannot be a vertex.

So, it means you cannot obtain the face as a result of Common operation between two solids and you're trying to mesh an empty shape.

Oliver R's picture

Thanks Eugeney for that link, I was not aware of that documentation and that is very useful.
How could I check that something bad is going to happen before I mesh the structure. It may not always be obvious that a 'degenerate' intersection is found. If I check with type = s1.ShapeType(); I see that this is type 2 and the resulting common operation is shape.ShapeType() is 0. Now, when I enlarge second box with setting gp_Pnt gp3 = gp_Pnt(0,0.5,0.5); such that these boxed overlap I also get a s1 type of 2 and a shape type of 0. How can I differentiate between these scenarios to avoid a crash?