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.
This commit is contained in:
Petru Conduraru
2026-07-16 14:41:22 +03:00
parent 821cf7b671
commit 09313eac40
+6
View File
@@ -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: