Browse Source

Merge pull request #437 from Jrius/TemporaryObject_ref_fix

Fix TemporaryCollectionItem reference bug
master
Adam Johnson 2 weeks ago committed by GitHub
parent
commit
22892ef702
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      korman/helpers.py

9
korman/helpers.py

@ -18,6 +18,7 @@ import bpy
from contextlib import contextmanager from contextlib import contextmanager
import math import math
from typing import * from typing import *
from uuid import uuid4
@contextmanager @contextmanager
def bmesh_from_object(bl): def bmesh_from_object(bl):
@ -62,12 +63,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