Browse Source

Fix TemporaryCollectionItem reference bug

pull/437/head
Jrius 2 weeks ago
parent
commit
23af1211cd
  1. 8
      korman/helpers.py

8
korman/helpers.py

@ -62,12 +62,14 @@ class GoodNeighbor:
@contextmanager @contextmanager
def TemporaryCollectionItem(collection): def TemporaryCollectionItem(collection):
item = collection.add() 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: try:
yield item yield item
finally: finally:
index = next((i for i, j in enumerate(collection) if j == item), None) index = collection.find(name)
if index is not None: collection.remove(index)
collection.remove(index)
class TemporaryObject: class TemporaryObject:
def __init__(self, obj, remove_func): def __init__(self, obj, remove_func):

Loading…
Cancel
Save