Skip to content

Commit 22892ef

Browse files
authored
Merge pull request #437 from Jrius/TemporaryObject_ref_fix
Fix TemporaryCollectionItem reference bug
2 parents 3939f6e + c6f2c4d commit 22892ef

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

korman/helpers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from contextlib import contextmanager
1919
import math
2020
from typing import *
21+
from uuid import uuid4
2122

2223
@contextmanager
2324
def bmesh_from_object(bl):
@@ -62,12 +63,14 @@ def __exit__(self, type, value, traceback):
6263
@contextmanager
6364
def TemporaryCollectionItem(collection):
6465
item = collection.add()
66+
# Blender may recreate the `item` instance as the collection grows and shrink...
67+
# Assign it a unique name so we know which item to delete later on.
68+
name = item.name = str(uuid4())
6569
try:
6670
yield item
6771
finally:
68-
index = next((i for i, j in enumerate(collection) if j == item), None)
69-
if index is not None:
70-
collection.remove(index)
72+
index = collection.find(name)
73+
collection.remove(index)
7174

7275
class TemporaryObject:
7376
def __init__(self, obj, remove_func):

0 commit comments

Comments
 (0)