From 1cb298fa9c41173344fba6be7988ef8e51aae631 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Sun, 1 Mar 2026 19:49:13 +0000 Subject: [PATCH] render: skip degenerate geometry instead of crashing Guard the face array reshape so elements whose triangulation is not divisible by 3 are silently dropped. Also wrap each _add_shape() call in a try/except so a broken shape never aborts the whole render. Generated with the assistance of an AI coding tool. --- src/ifcquery/ifcquery/render.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ifcquery/ifcquery/render.py b/src/ifcquery/ifcquery/render.py index 86b9d62bb4..6c4c1a559f 100644 --- a/src/ifcquery/ifcquery/render.py +++ b/src/ifcquery/ifcquery/render.py @@ -68,7 +68,10 @@ def _add_shape( if verts.size == 0: return - faces = np.array(geom.faces, dtype=int).reshape(-1, 3) + raw_faces = np.array(geom.faces, dtype=int) + if raw_faces.size == 0 or raw_faces.size % 3 != 0: + return # degenerate geometry from kernel — skip silently + faces = raw_faces.reshape(-1, 3) material_ids = np.array(geom.material_ids, dtype=int) is_subject = highlight_ids is not None and shape.product.id() in highlight_ids @@ -163,7 +166,10 @@ def render( plotter.background_color = "white" while True: - _add_shape(iterator.get(), plotter, highlight_ids=frozenset(element_ids) if element_ids else None) + try: + _add_shape(iterator.get(), plotter, highlight_ids=frozenset(element_ids) if element_ids else None) + except Exception: + pass # skip broken shapes, keep rendering the rest if not iterator.next(): break