From 66681a69df0d41c9e8bb97796717058b9f7b95df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 12 Feb 2019 12:31:05 +0100 Subject: [PATCH] Fixed crash where collection children are ID blocks instead of GR blocks Not sure when/how that happens, but it happened on a lighting file of the Spring project, when linking in a nested collection of which parts where also linked in from other blend files. --- blender_asset_tracer/blendfile/__init__.py | 6 +++++- blender_asset_tracer/trace/expanders.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/blender_asset_tracer/blendfile/__init__.py b/blender_asset_tracer/blendfile/__init__.py index 7fd00c5..308be8b 100644 --- a/blender_asset_tracer/blendfile/__init__.py +++ b/blender_asset_tracer/blendfile/__init__.py @@ -498,9 +498,13 @@ class BlendFileBlock: def dna_type(self) -> dna.Struct: return self.bfile.structs[self.sdna_index] + @property + def dna_type_id(self) -> bytes: + return self.dna_type.dna_type_id + @property def dna_type_name(self) -> str: - return self.dna_type.dna_type_id.decode('ascii') + return self.dna_type_id.decode('ascii') @property def id_name(self) -> typing.Optional[bytes]: diff --git a/blender_asset_tracer/trace/expanders.py b/blender_asset_tracer/trace/expanders.py index 67aec8a..5733840 100644 --- a/blender_asset_tracer/trace/expanders.py +++ b/blender_asset_tracer/trace/expanders.py @@ -123,7 +123,7 @@ def _expand_curve(block: blendfile.BlendFileBlock): @dna_code('GR') def _expand_group(block: blendfile.BlendFileBlock): - log.debug('Block: %s', block) + log.debug('Collection/group Block: %s (name=%s)', block, block.id_name) objects = block.get_pointer((b'gobject', b'first')) for item in iterators.listbase(objects): @@ -140,7 +140,15 @@ def _expand_group(block: blendfile.BlendFileBlock): subcoll = child.get_pointer(b'collection') if subcoll is None: continue - log.debug('recursing into child collection %s', subcoll.id_name) + + if subcoll.dna_type_id == b'ID': + # No idea when this happens, but it happened in the Chimes + # set of the Spring project. This fixed it. + yield subcoll + continue + + log.debug('recursing into child collection %s (name=%r, type=%r)', + subcoll, subcoll.id_name, subcoll.dna_type_name) yield from _expand_group(subcoll)