From a72ca6f4004d14d2073f2daff2c65861458eb0dd Mon Sep 17 00:00:00 2001 From: Roman Claudiu Date: Sun, 8 Nov 2026 01:52:52 +0200 Subject: [PATCH 1/2] Raise in free fillet and chamfer when the operation fails cadquery.func.fillet and cadquery.func.chamfer called Shape() on the builder even when Build() had failed. Shape() then builds again, and the second build of BRepFilletAPI_MakeFillet / MakeChamfer segfaults inside OCCT. Check IsDone() right after Build() and raise ValueError instead. Fixes #2114 --- cadquery/occ_impl/shapes.py | 10 ++++++++++ tests/test_free_functions.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 40dd9dccf..7ee98beeb 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -7530,6 +7530,7 @@ def fillet( :param history: If given, the operation is recorded in this history. :param name: Name under which the operation is recorded in ``history``. :return: The filleted shape. + :raises ValueError: If the fillet cannot be built. """ builder = BRepFilletAPI_MakeFillet(_get_one(s, (Shell, Solid)).wrapped,) @@ -7539,6 +7540,10 @@ def fillet( builder.Build() + # fail clearly; calling Shape() on a failed builder rebuilds it and crashes + if not builder.IsDone(): + raise ValueError("Fillet failed, try a smaller radius or fewer edges") + _update_history(history, name, [s, edges], builder) return _compound_or_shape(builder.Shape()) @@ -7560,6 +7565,7 @@ def chamfer( :param history: If given, the operation is recorded in this history. :param name: Name under which the operation is recorded in ``history``. :return: The chamfered shape. + :raises ValueError: If the chamfer cannot be built. """ builder = BRepFilletAPI_MakeChamfer(_get_one(s, (Shell, Solid)).wrapped,) @@ -7569,6 +7575,10 @@ def chamfer( builder.Build() + # fail clearly; calling Shape() on a failed builder rebuilds it and crashes + if not builder.IsDone(): + raise ValueError("Chamfer failed, try a smaller distance or fewer edges") + _update_history(history, name, [s, edges], builder) return _compound_or_shape(builder.Shape()) diff --git a/tests/test_free_functions.py b/tests/test_free_functions.py index 3802aefd8..344cb313e 100644 --- a/tests/test_free_functions.py +++ b/tests/test_free_functions.py @@ -1023,6 +1023,16 @@ def test_chamfer(): assert r.faces(">Z").Area() < 1 +@pytest.mark.parametrize("op", [fillet, chamfer]) +def test_fillet_chamfer_failure(op): + + b = box(1, 1, 1) + + # too large to fit, so the operation fails; it must raise instead of crashing + with raises(ValueError): + op(b, b.edges(), 0.5) + + @pytest.mark.parametrize("sel, n", [("|Z", 4), (">X and >Y", 1)]) def test_fillet_chamfer_methods_shape_arg(sel, n): From b871425b5d2a64eea3e68e7c2df8548359372994 Mon Sep 17 00:00:00 2001 From: AU Date: Sun, 15 Nov 2026 18:37:21 +0100 Subject: [PATCH 2/2] Apply batched suggestions from code review Co-authored-by: AU --- cadquery/occ_impl/shapes.py | 2 -- tests/test_free_functions.py | 8 +++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 7ee98beeb..c3210b2a6 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -7540,7 +7540,6 @@ def fillet( builder.Build() - # fail clearly; calling Shape() on a failed builder rebuilds it and crashes if not builder.IsDone(): raise ValueError("Fillet failed, try a smaller radius or fewer edges") @@ -7575,7 +7574,6 @@ def chamfer( builder.Build() - # fail clearly; calling Shape() on a failed builder rebuilds it and crashes if not builder.IsDone(): raise ValueError("Chamfer failed, try a smaller distance or fewer edges") diff --git a/tests/test_free_functions.py b/tests/test_free_functions.py index 344cb313e..52437f321 100644 --- a/tests/test_free_functions.py +++ b/tests/test_free_functions.py @@ -1024,13 +1024,11 @@ def test_chamfer(): @pytest.mark.parametrize("op", [fillet, chamfer]) -def test_fillet_chamfer_failure(op): +def test_fillet_chamfer_raises(box_shape, op): - b = box(1, 1, 1) - - # too large to fit, so the operation fails; it must raise instead of crashing + # too large to fit, the op must raise instead of crashing with raises(ValueError): - op(b, b.edges(), 0.5) + op(box_shape, box_shape.edges(), 0.5) @pytest.mark.parametrize("sel, n", [("|Z", 4), (">X and >Y", 1)])