From 23af1211cdcf13a597a10fb9e604b331d1d365b7 Mon Sep 17 00:00:00 2001 From: Jrius <2261279+Jrius@users.noreply.github.com> Date: Mon, 24 Feb 2025 18:50:22 +0100 Subject: [PATCH] Fix TemporaryCollectionItem reference bug --- korman/helpers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/korman/helpers.py b/korman/helpers.py index 35c0176..eaa1c0c 100644 --- a/korman/helpers.py +++ b/korman/helpers.py @@ -62,12 +62,14 @@ class GoodNeighbor: @contextmanager def TemporaryCollectionItem(collection): item = collection.add() + # Blender may recreate the `item` instance as the collection grows and shrink... + # Assign it a unique name so we know which item to delete later on. + name = item.name = str(uuid4()) try: yield item finally: - index = next((i for i, j in enumerate(collection) if j == item), None) - if index is not None: - collection.remove(index) + index = collection.find(name) + collection.remove(index) class TemporaryObject: def __init__(self, obj, remove_func):