From 09313eac402ca48774139aa6f8211e185f7b7ce3 Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Thu, 16 Jul 2026 14:41:22 +0300 Subject: [PATCH] Bonsai: tolerate an already-removed mesh/curve/camera data-block in delete_data (#5793) tool.Geometry.delete_data() only guarded against TypeError (passing the wrong bpy.data collection). If the data-block had already been freed elsewhere between the earlier has_data_users() check and this deferred cleanup call (observed after a busy sequence of switch_representation calls followed by remove_representation), bpy.data.meshes.remove() raises an uncaught ReferenceError, which aborts the whole IFC operator transaction with a traceback matching the one reported in #5793. Catch ReferenceError too and treat an already-removed data-block as a no-op, since the desired end state (the data being gone) is already met. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/tool/geometry.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 08abd38b22..5d4c6f4ca8 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -373,6 +373,12 @@ class Geometry(bonsai.core.tool.Geometry): bpy.data.curves.remove(data) except TypeError: bpy.data.cameras.remove(data) + except ReferenceError: + # The data-block was already removed elsewhere (e.g. purged as an + # orphan in between an earlier "has data users" check and this + # deferred cleanup call). It's already gone, so there's nothing + # left to do. + pass @classmethod def is_locked(cls, element: ifcopenshell.entity_instance) -> bool: