bugfix: work on a copy of the object list to prevent error
hiding/unhinding while interating on objects can void an object, giving back None), because Blender's cached object list is invalidated
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ bl_info = {
|
|||||||
"name": "Render Toolbox",
|
"name": "Render Toolbox",
|
||||||
"description": "Setup outputs and perform cheks for rendering",
|
"description": "Setup outputs and perform cheks for rendering",
|
||||||
"author": "Samuel Bernou",
|
"author": "Samuel Bernou",
|
||||||
"version": (2, 0, 0),
|
"version": (2, 0, 1),
|
||||||
"blender": (5, 2, 0),
|
"blender": (5, 2, 0),
|
||||||
"location": "View3D",
|
"location": "View3D",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
|
|||||||
@@ -805,9 +805,11 @@ def apply_collection_states(collection, context=None):
|
|||||||
return ({'WARNING'}, f"No stored state for '{key}'")
|
return ({'WARNING'}, f"No stored state for '{key}'")
|
||||||
# return {'CANCELLED'}
|
# return {'CANCELLED'}
|
||||||
|
|
||||||
|
## Collect objects before changing visibility (can invalidate all_objects cache)
|
||||||
|
all_objects = {o.name: o for o in collection.all_objects}
|
||||||
for obj_name, obj_state in state['objects'].items():
|
for obj_name, obj_state in state['objects'].items():
|
||||||
# obj = context.scene.objects.get(obj_name)
|
# obj = context.scene.objects.get(obj_name)
|
||||||
obj = collection.all_objects.get(obj_name)
|
obj = all_objects.get(obj_name)
|
||||||
if obj:
|
if obj:
|
||||||
obj.hide_viewport = obj_state.get('hide_viewport', False)
|
obj.hide_viewport = obj_state.get('hide_viewport', False)
|
||||||
obj.hide_render = obj_state.get('hide_render', False)
|
obj.hide_render = obj_state.get('hide_render', False)
|
||||||
|
|||||||
@@ -103,7 +103,9 @@ def outliner_conform(apply=False, context=None):
|
|||||||
affected_items['collections'][vlc] = col_attrs
|
affected_items['collections'][vlc] = col_attrs
|
||||||
|
|
||||||
if affect_target in {'ALL', 'OBJECT'}:
|
if affect_target in {'ALL', 'OBJECT'}:
|
||||||
for obj in ref_collection.all_objects:
|
## Iterate on a copy: changing visibility can invalidate all_objects cache while iterating
|
||||||
|
## (iteration then yields None and stops early)
|
||||||
|
for obj in list(ref_collection.all_objects):
|
||||||
obj_attrs = []
|
obj_attrs = []
|
||||||
if conform_selectability and obj.hide_select != ref_collection.hide_select:
|
if conform_selectability and obj.hide_select != ref_collection.hide_select:
|
||||||
if apply: obj.hide_select = ref_collection.hide_select
|
if apply: obj.hide_select = ref_collection.hide_select
|
||||||
|
|||||||
Reference in New Issue
Block a user