Evict stale snap_objs cache entries on ReferenceError

When a Blender object is deleted while the snap cache still holds a
SnapObj referencing it, accessing snap_obj.obj.name raises ReferenceError.
Catch it, evict the dead entry, and let the caller retry cleanly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ryan Schultz
2026-08-04 12:56:44 -05:00
parent f63d02b2b4
commit 8c5d33f9e5
+6 -1
View File
@@ -970,7 +970,12 @@ class Raycast(bonsai.core.tool.Raycast):
if obj.data is None or not isinstance(obj.data, bpy.types.Mesh):
return None
for i, snap_obj in enumerate(cls.snap_objs):
if obj.name == snap_obj.obj.name:
try:
cached_name = snap_obj.obj.name
except ReferenceError:
cls.snap_objs.pop(i)
break
if obj.name == cached_name:
# Fast O(1) invalidation: vertex count change (mesh edit) or
# world matrix change (object moved/rotated).
if len(obj.data.vertices) != len(snap_obj.verts_3d):