Skip to content

Commit ea4104d

Browse files
committed
fix: skip IFC relations with unset relating/related attributes (#217)
Virtual IfcRelSpaceBoundary entries have RelatedBuildingElement unset ($), which processRelations dereferenced as .value on null and crashed. Null/unset relating and related attributes are now filtered out and the relation is skipped when nothing valid remains. Also removes the per-error 100ms setTimeout in the catch, which inflated conversion time on files with many such entries. Closes #217
1 parent 6a4391b commit ea4104d

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

packages/fragments/src/Importers/IfcImporter/src/properties/property-processor.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,28 +587,48 @@ export class IfcPropertyProcessor {
587587
attr.startsWith("Related"),
588588
);
589589
if (!(relatingKey && relatedKey)) continue;
590-
const relatingID = attrs[relatingKey].value;
590+
591+
// The relating attribute may be unset/null in valid IFC. Skip if so.
592+
const relatingAttr = attrs[relatingKey];
593+
if (
594+
!relatingAttr ||
595+
relatingAttr.value === undefined ||
596+
relatingAttr.value === null
597+
) {
598+
continue;
599+
}
600+
const relatingID = relatingAttr.value;
591601

592602
const rawRelatedIDs = attrs[relatedKey];
593603
let relatedIDs: number[] = [];
594604
if (Array.isArray(rawRelatedIDs)) {
595-
relatedIDs = rawRelatedIDs.map(
596-
({ value }: { value: number }) => value,
597-
);
598-
} else {
605+
// Filter out null entries (e.g. virtual boundaries with no element).
606+
relatedIDs = rawRelatedIDs
607+
.filter(
608+
(related) =>
609+
related &&
610+
related.value !== undefined &&
611+
related.value !== null,
612+
)
613+
.map(({ value }: { value: number }) => value);
614+
} else if (
615+
rawRelatedIDs &&
616+
rawRelatedIDs.value !== undefined &&
617+
rawRelatedIDs.value !== null
618+
) {
599619
relatedIDs = [rawRelatedIDs.value];
600620
}
601621

622+
// Nothing valid to relate (e.g. a virtual space boundary) → skip.
623+
if (relatedIDs.length === 0) continue;
624+
602625
this.addRelation(relatingID, forRelating, relatedIDs);
603626
for (const relatedID of relatedIDs) {
604627
this.addRelation(relatedID, forRelated, [relatingID]);
605628
}
606629
} catch (e) {
607630
console.log(`Problem reading relations for ${expressID}`);
608631
console.log(e);
609-
await new Promise((resolve) => {
610-
setTimeout(resolve, 100);
611-
});
612632
continue;
613633
}
614634
}

0 commit comments

Comments
 (0)