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.
This commit is contained in:
Sybren A. Stüvel 2019-02-12 12:31:05 +01:00
parent bf7d2b1e27
commit 66681a69df
2 changed files with 15 additions and 3 deletions

View File

@ -498,9 +498,13 @@ class BlendFileBlock:
def dna_type(self) -> dna.Struct: def dna_type(self) -> dna.Struct:
return self.bfile.structs[self.sdna_index] return self.bfile.structs[self.sdna_index]
@property
def dna_type_id(self) -> bytes:
return self.dna_type.dna_type_id
@property @property
def dna_type_name(self) -> str: def dna_type_name(self) -> str:
return self.dna_type.dna_type_id.decode('ascii') return self.dna_type_id.decode('ascii')
@property @property
def id_name(self) -> typing.Optional[bytes]: def id_name(self) -> typing.Optional[bytes]:

View File

@ -123,7 +123,7 @@ def _expand_curve(block: blendfile.BlendFileBlock):
@dna_code('GR') @dna_code('GR')
def _expand_group(block: blendfile.BlendFileBlock): 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')) objects = block.get_pointer((b'gobject', b'first'))
for item in iterators.listbase(objects): for item in iterators.listbase(objects):
@ -140,7 +140,15 @@ def _expand_group(block: blendfile.BlendFileBlock):
subcoll = child.get_pointer(b'collection') subcoll = child.get_pointer(b'collection')
if subcoll is None: if subcoll is None:
continue 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) yield from _expand_group(subcoll)