Repository navigation
func.fillet / func.chamfer segfault instead of raising when the operation fails #2114
Description
cadquery.func.fillet and cadquery.func.chamfer call builder.Build() and then builder.Shape(). If the build failed, BRepBuilderAPI_MakeShape::Shape() calls Build() again, and the second build of BRepFilletAPI_MakeFillet / MakeChamfer segfaults inside OCCT. So a fillet that should raise StdFail_NotDone kills the process. The method Solid.fillet builds only once and raises correctly.
To Reproduce
from cadquery.func import box, fillet
b = box(10, 10, 10)
fillet(b, b.edges(), 5) # segfault; b.fillet(5, b.Edges()) raises StdFail_NotDonechamfer(b, b.edges(), 5) crashes the same way.
Backtrace
Python (python -X faulthandler; this is the complete stack):
Fatal Python error: Segmentation fault
Current thread 0x00007ba959a21780 [python] (most recent call first):
File ".../site-packages/cadquery/occ_impl/shapes.py", line 7225 in fillet
File "mre_fillet_crash.py", line 4 in <module>
Native (C stack printed by faulthandler; no gdb/lldb available; Python interpreter frames omitted, symbols demangled):
libTKFillet.so.8.0.1 ChFi3d_Builder::UpdateTolesp()+0x28
libTKFillet.so.8.0.1 ChFi3d_Builder::Compute()+0x1e
libTKFillet.so.8.0.1 BRepFilletAPI_MakeFillet::Build(Message_ProgressRange const&)+0x1a
libTKTopAlgo.so.8.0.1 BRepBuilderAPI_MakeShape::Shape()+0x3b
OCP.cpython-314-x86_64-linux-gnu.so +0x141afcb
Suggested fix
Check the result before anything else touches the builder:
builder.Build()
+ if not builder.IsDone():
+ raise ValueError("Fillet failed")
+
_update_history(history, name, [s, edges], builder)and the same in chamfer (the same kind of guard as #2106 adds for n_sided). With this change the example raises ValueError, and tests/test_free_functions.py passes (apart from two font tests that fail without Arial installed). I can open a PR if that helps.
Environment
OS:
Ubuntu 26.04.1 LTS, x86_64
Was CadQuery installed using Conda?: No. Fresh virtual environment created with uv (uv venv --python 3.14, uv-managed CPython 3.14.8), then uv pip install of a git checkout of master (5f5bc62), which pulls the cadquery-ocp 8.0.1.1 wheel from PyPI. The same crash occurs with the release: cadquery 2.8.0 and cadquery-ocp 7.9.3.1.1 from PyPI.
Output of uv pip list from the active environment:
pip list
Package Version
------------------ -----------
aiohappyeyeballs 2.7.1
aiohttp 3.14.5
aiosignal 1.4.0
attrs 26.1.0
cadquery 2.9.0.dev0
cadquery-ocp 8.0.1.1.0
cadquery-ocp-proxy 8.0.1.1.0
casadi 3.8.1
contourpy 1.4.0
cycler 0.12.1
ezdxf 1.4.5
fonttools 4.67.0
frozenlist 1.8.0
idna 3.20
iniconfig 2.3.1
kiwisolver 1.5.1
llvmlite 0.50.0
matplotlib 3.11.2
more-itertools 11.2.1
msgpack 1.2.3
multidict 7.1.0
multimethod 2.1
nlopt 2.11.0
numba 0.68.0
numpy 2.5.4
packaging 26.3
pillow 13.0.0
pluggy 1.7.0
propcache 0.5.4
pygments 2.21.0
pyparsing 3.3.3
pytest 9.1.1
python-dateutil 2.9.0.post0
pyyaml 6.0.3
runtype 0.5.3
scipy 1.18.1
six 1.17.0
trame 4.0.0
trame-client 4.1.4
trame-common 1.2.9
trame-components 2.5.0
trame-server 4.1.0
trame-vtk 2.11.17
trame-vuetify 3.3.0
typing-extensions 4.16.0
vtk 9.6.2
wslink 2.6.0
yarl 1.25.1
Using:
Python interpreter
Activity