Warning iterator invalidation in removeEntity

This commit is contained in:
fluider
2020-09-30 09:38:01 +02:00
committed by Thomas Krijnen
parent b4f4d9b3c5
commit e3831be16e
+8
View File
@@ -1764,6 +1764,14 @@ void IfcFile::removeEntity(IfcUtil::IfcBaseClass* entity) {
const unsigned id = entity->data().id(); const unsigned id = entity->data().id();
IfcUtil::IfcBaseClass* file_entity = instance_by_id(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<IfcEntityList> 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 // 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 // instance to be retained. For example: when deleting an IfcRepresentation, the
// individual IfcRepresentationItems can not be deleted if an IfcStyledItem is // individual IfcRepresentationItems can not be deleted if an IfcStyledItem is