From 2ab3b3ab5bb794b35b638c2c1f88f7fbe046eea4 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 15 Nov 2011 11:05:35 +0000 Subject: [PATCH] Changed the semantic and the return value of the generic DeleteAttribute (e.g. the one that does not take a type) ** It must not crash if you try to delete a non existing attribute, because you do not have a way of asking for a handle of an attribute for which you do not know the type. --- vcg/complex/allocate.h | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index 40c60d79..e9881ec3 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -989,14 +989,18 @@ public: assert(0); } + // Generic DeleteAttribute. + // It must not crash if you try to delete a non existing attribute, + // because you do not have a way of asking for a handle of an attribute for which you do not know the type. static - void DeletePerVertexAttribute( MeshType & m, std::string name){ + bool DeletePerVertexAttribute( MeshType & m, std::string name){ AttrIterator i; PointerToAttribute h1; h1._name = name; i = m.vert_attr.find(h1); - assert(i!=m.vert_attr.end()); + if(i==m.vert_attr.end()) return false; delete ((SimpleTempDataBase*)(*i)._handle); m.vert_attr.erase(i); + return true; } @@ -1077,14 +1081,18 @@ public: assert(0); } + // Generic DeleteAttribute. + // It must not crash if you try to delete a non existing attribute, + // because you do not have a way of asking for a handle of an attribute for which you do not know the type. static - void DeletePerEdgeAttribute( MeshType & m, std::string name){ + bool DeletePerEdgeAttribute( MeshType & m, std::string name){ AttrIterator i; PointerToAttribute h1; h1._name = name; i = m.edge_attr.find(h1); - assert(i!=m.edge_attr.end()); - delete ((SimpleTempDataBase*)(*i)._handle); + if(i==m.edge_attr.end()) return false; + delete ((SimpleTempDataBase*)(*i)._handle); m.edge_attr.erase(i); + return true; } /// Per Face Attributes @@ -1176,14 +1184,18 @@ public: assert(0); } + // Generic DeleteAttribute. + // It must not crash if you try to delete a non existing attribute, + // because you do not have a way of asking for a handle of an attribute for which you do not know the type. static - void DeletePerFaceAttribute( MeshType & m, std::string name){ + bool DeletePerFaceAttribute( MeshType & m, std::string name){ AttrIterator i; PointerToAttribute h1; h1._name = name; i = m.face_attr.find(h1); - assert(i!=m.face_attr.end()); - delete ((SimpleTempDataBase*)(*i)._handle); + if(i==m.face_attr.end()) return false; + delete ((SimpleTempDataBase*)(*i)._handle); m.face_attr.erase(i); + return true; } /// Per Mesh Attributes