From 3f285ea6390578559c8795749cd02fe5d7160c01 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 27 Nov 2014 09:22:58 +0000 Subject: [PATCH] Prevent another exception being thrown upon adding entity instances to a file, as reported by ch0kee --- src/ifcparse/IfcParse.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index bd90b09827..cec07b89bb 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -925,19 +925,23 @@ void IfcFile::AddEntity(IfcUtil::IfcBaseClass* entity) { for (IfcEntityList::it it = entity_attributes->begin(); it != entity_attributes->end(); ++it) { IfcUtil::IfcBaseClass* entity_attribute = *it; try { - if (entity_attribute->entity->isWritable()) { - if ( ! entity_attribute->entity->file ) { - entity_attribute->entity->file = this; + if (!IfcSchema::Type::IsSimple(entity_attribute->type())) { + // At this point simple types are IfcSelectHelper instances + // which are not writable and do not have an instance name. + if (entity_attribute->entity->isWritable()) { + if ( ! entity_attribute->entity->file ) { + entity_attribute->entity->file = this; + } + entity_attribute->entity->isWritable()->setId(); } - entity_attribute->entity->isWritable()->setId(); + unsigned entity_attribute_id = entity_attribute->entity->id(); + IfcEntityList::ptr refs = EntitiesByReference(entity_attribute_id); + if (!refs) { + refs = IfcEntityList::ptr(new IfcEntityList); + byref[entity_attribute_id] = refs; + } + refs->push(entity); } - unsigned entity_attribute_id = entity_attribute->entity->id(); - IfcEntityList::ptr refs = EntitiesByReference(entity_attribute_id); - if (!refs) { - refs = IfcEntityList::ptr(new IfcEntityList); - byref[entity_attribute_id] = refs; - } - refs->push(entity); } catch (IfcParse::IfcException&) {} } }