From 788b9ce02b046a201e9c8fcf9c8979e57d74359f Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Sat, 27 Mar 2021 09:59:13 +0000
Subject: [PATCH] fix for #1289: make sure to delete removed entities in GModel
 during sync also with unbindWithoutChecks(): otherwise if some tags are
 reused (because entities have previsously been removed before the unbind, but
 without a sync between the two operations) we would find the (wrong) original
 entities in the GModel.

(cherry picked from commit 72b91c2553092fea8e22a61b7b0738a8a09be44c)
---
 Geo/GModelIO_OCC.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp
index f6241e14d5..cf528ad26f 100644
--- a/Geo/GModelIO_OCC.cpp
+++ b/Geo/GModelIO_OCC.cpp
@@ -583,6 +583,7 @@ void OCC_Internals::unbindWithoutChecks(TopoDS_Shape shape)
       int tag = _solidTag.Find(solid);
       _solidTag.UnBind(solid);
       _tagSolid.UnBind(tag);
+      _toRemove.insert(std::make_pair(3, tag));
     }
   }
   for(exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next()) {
@@ -591,6 +592,7 @@ void OCC_Internals::unbindWithoutChecks(TopoDS_Shape shape)
       int tag = _shellTag.Find(shell);
       _shellTag.UnBind(shell);
       _tagShell.UnBind(tag);
+      _toRemove.insert(std::make_pair(-2, tag));
     }
   }
   for(exp0.Init(shape, TopAbs_FACE); exp0.More(); exp0.Next()) {
@@ -599,6 +601,7 @@ void OCC_Internals::unbindWithoutChecks(TopoDS_Shape shape)
       int tag = _faceTag.Find(face);
       _faceTag.UnBind(face);
       _tagFace.UnBind(tag);
+      _toRemove.insert(std::make_pair(2, tag));
     }
   }
   for(exp0.Init(shape, TopAbs_WIRE); exp0.More(); exp0.Next()) {
@@ -607,6 +610,7 @@ void OCC_Internals::unbindWithoutChecks(TopoDS_Shape shape)
       int tag = _wireTag.Find(wire);
       _wireTag.UnBind(wire);
       _tagWire.UnBind(tag);
+      _toRemove.insert(std::make_pair(-1, tag));
     }
   }
   for(exp0.Init(shape, TopAbs_EDGE); exp0.More(); exp0.Next()) {
@@ -615,6 +619,7 @@ void OCC_Internals::unbindWithoutChecks(TopoDS_Shape shape)
       int tag = _edgeTag.Find(edge);
       _edgeTag.UnBind(edge);
       _tagEdge.UnBind(tag);
+      _toRemove.insert(std::make_pair(1, tag));
     }
   }
   for(exp0.Init(shape, TopAbs_VERTEX); exp0.More(); exp0.Next()) {
@@ -623,6 +628,7 @@ void OCC_Internals::unbindWithoutChecks(TopoDS_Shape shape)
       int tag = _vertexTag.Find(vertex);
       _vertexTag.UnBind(vertex);
       _tagVertex.UnBind(tag);
+      _toRemove.insert(std::make_pair(0, tag));
     }
   }
 }
-- 
GitLab