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:
Pullusb
2026-09-30 15:59:19 +02:00
parent d650ec8c98
commit c2073d7c11
3 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -805,9 +805,11 @@ def apply_collection_states(collection, context=None):
return ({'WARNING'}, f"No stored state for '{key}'")
# 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():
# obj = context.scene.objects.get(obj_name)
obj = collection.all_objects.get(obj_name)
obj = all_objects.get(obj_name)
if obj:
obj.hide_viewport = obj_state.get('hide_viewport', False)
obj.hide_render = obj_state.get('hide_render', False)