Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random failures (memory corruption?) in BRepOffsetAPI_MakeFilling #716

Open
blechta opened this issue Jul 15, 2019 · 1 comment
Open

Random failures (memory corruption?) in BRepOffsetAPI_MakeFilling #716

blechta opened this issue Jul 15, 2019 · 1 comment

Comments

@blechta
Copy link

blechta commented Jul 15, 2019

Original downstream issue: https://gitlab.onelab.info/gmsh/gmsh/issues/596
Version: OCE-0.18.3
MWE:

from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeVertex
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeWire
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeFilling
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_EDGE
from OCC.Core.GeomAbs import GeomAbs_C0
from OCC.Core.gp import gp_Pnt
from OCC.Core.TColgp import TColgp_Array1OfPnt
from OCC.Core.Geom import Geom_BezierCurve
from OCC.Core.BRep import BRep_Tool


p1 = gp_Pnt(0,0,2)
p2 = gp_Pnt(1,0,2)
p3 = gp_Pnt(0,1,2)
p4 = gp_Pnt(5.000000e-01,0,1.500000e+00)
p5 = gp_Pnt(0,5.000000e-01,2.500000e+00)
p6 = gp_Pnt(5.000000e-01,5.000000e-01,1.500000e+00)
p7 = gp_Pnt(5.000000e-01,0,1)
p8 = gp_Pnt(0,5.000000e-01,3)
p9 = gp_Pnt(5.000000e-01,5.000000e-01,1)

v1 = BRepBuilderAPI_MakeVertex(p1).Vertex()
v2 = BRepBuilderAPI_MakeVertex(p2).Vertex()
v3 = BRepBuilderAPI_MakeVertex(p3).Vertex()

ctrl1 = TColgp_Array1OfPnt(1, 3)
ctrl1.SetValue(1, p1)
ctrl1.SetValue(2, p7)
ctrl1.SetValue(3, p2)

ctrl2 = TColgp_Array1OfPnt(1, 3)
ctrl2.SetValue(1, p3)
ctrl2.SetValue(2, p8)
ctrl2.SetValue(3, p1)

ctrl3 = TColgp_Array1OfPnt(1, 3)
ctrl3.SetValue(1, p2)
ctrl3.SetValue(2, p9)
ctrl3.SetValue(3, p3)

curve1 = Geom_BezierCurve(ctrl1)
curve2 = Geom_BezierCurve(ctrl2)
curve3 = Geom_BezierCurve(ctrl3)

edge1 = BRepBuilderAPI_MakeEdge(curve1, v1, v2).Edge()
edge2 = BRepBuilderAPI_MakeEdge(curve2, v3, v1).Edge()
edge3 = BRepBuilderAPI_MakeEdge(curve3, v2, v3).Edge()

wire = BRepBuilderAPI_MakeWire()
wire.Add(edge1)
wire.Add(edge2)
wire.Add(edge3)

wire = wire.Wire()
assert wire.Closed()

filling = BRepOffsetAPI_MakeFilling()
exp0 = TopExp_Explorer()
exp0.Init(wire, TopAbs_EDGE)

while exp0.More():
    filling.Add(exp0.Current(), GeomAbs_C0)
    exp0.Next()

print(BRep_Tool.Pnt(v1).Coord())

try:
    filling.Build()
finally:
    print(BRep_Tool.Pnt(v1).Coord())

Expected behavior: print

(0.0, 0.0, 2.0)
(0.0, 0.0, 2.0)

and exit.

Observed behavior: randomly one of the following:

(0.0, 0.0, 2.0)
(0.276393202249936, 0.361803398875032, 2.0)
Traceback (most recent call last):
  File "gmsh-issue-596.py", line 70, in <module>
    filling.Build()
RuntimeError: Standard_NoSuchObject
TCollection_List::Remove
wrapper details:
  * symname: BRepBuilderAPI_MakeShape_Build
  * wrapname: _wrap_BRepBuilderAPI_MakeShape_Build
  * fulldecl: void BRepBuilderAPI_MakeShape::Build()

or

(0.0, 0.0, 2.0)
(0.0, 0.0, 2.0)
Traceback (most recent call last):
  File "gmsh-issue-596.py", line 70, in <module>
    filling.Build()
RuntimeError: Standard_Failure
Wire is not closed
wrapper details:
  * symname: BRepBuilderAPI_MakeShape_Build
  * wrapname: _wrap_BRepBuilderAPI_MakeShape_Build
  * fulldecl: void BRepBuilderAPI_MakeShape::Build()
@blechta
Copy link
Author

blechta commented Jul 15, 2019

Note that changing p1 to

p1 = gp_Pnt(0.1,0,2)

makes the problem miraculously go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant