diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index c0f8a28839..9f06bd0334 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1763,6 +1763,14 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) { void IfcFile::removeEntity(IfcUtil::IfcBaseClass* entity) { const unsigned id = entity->data().id(); IfcUtil::IfcBaseClass* file_entity = instance_by_id(id); + + // Attention when running removeEntity inside a loop over a list of entities to be removed. + // This invalidates the iterator. A workaround is to reverse the loop: + // boost::shared_ptr entities = ...; + // for (auto it = entities->end() - 1; it >= entities->begin(); --it) { + // IfcUtil::IfcBaseClass *const inst = *it; + // model->removeEntity(inst); + // } // TODO: Create a set of weak relations. Inverse relations that do not dictate an // instance to be retained. For example: when deleting an IfcRepresentation, the @@ -2173,4 +2181,4 @@ void IfcParse::IfcFile::build_inverses() { for (auto& pair : *this) { build_inverses_(pair.second); } -} \ No newline at end of file +}