From f40f7585edb105cb959f632a66ae00fb2cd9860e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Jun 2019 12:24:16 +0200 Subject: [PATCH] Prevent error when modifying actions dict --- blender_asset_tracer/pack/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/blender_asset_tracer/pack/__init__.py b/blender_asset_tracer/pack/__init__.py index a3584a4..c48a9ed 100644 --- a/blender_asset_tracer/pack/__init__.py +++ b/blender_asset_tracer/pack/__init__.py @@ -339,15 +339,25 @@ class Packer: only once. """ - for action in self._actions.values(): + # Take a copy so we can modify self._actions in the loop. + actions = set(self._actions.values()) + + while actions: + action = actions.pop() + if action.path_action != PathAction.FIND_NEW_LOCATION: # This asset doesn't require a new location, so no rewriting necessary. continue for usage in action.usages: bfile_path = usage.block.bfile.filepath.absolute().resolve() + insert_new_action = bfile_path not in self._actions + self._actions[bfile_path].rewrites.append(usage) + if insert_new_action: + actions.add(self._actions[bfile_path]) + def _path_in_project(self, path: pathlib.Path) -> bool: try: # MUST use resolve(), otherwise /path/to/proj/../../asset.png