applied patch [ #4207 ] Boolean operations fix
authorErwin Coumans <blender@erwincoumans.com>
Fri, 2 Jun 2006 18:17:40 +0000 (18:17 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Fri, 2 Jun 2006 18:17:40 +0000 (18:17 +0000)
Also fixed other problems with STL iterators/vectors, that only show up under Visual Studio 2005.

See also http://projects.blender.org/pipermail/bf-committers/2006-May/014608.html

intern/bsp/intern/BSP_CSGMesh_CFIterator.h
intern/decimation/intern/LOD_EdgeCollapser.cpp
intern/decimation/intern/LOD_MeshPrimitives.cpp

index 77ba076885f9a64227c4c1d46afc4a6b463dfafe..9cd237873c798bf931c46fa18c8e8edfdc4a23d4 100755 (executable)
@@ -69,7 +69,8 @@ BSP_CSGMesh_VertexIt_Done(
        // assume CSG_IteratorPtr is of the correct type.
        BSP_CSGMesh_VertexIt * vertex_it = (BSP_CSGMesh_VertexIt *)it;
 
-       if (vertex_it->pos < &(*vertex_it->mesh->VertexSet().end())) return 0;
+       /* dereferencing iterator::end() is illegal, so we dereference 1 before it */
+       if (vertex_it->pos <= &(*(vertex_it->mesh->VertexSet().end() -1) )) return 0;
        return 1;
 };
 
@@ -161,7 +162,8 @@ BSP_CSGMesh_FaceIt_Done(
        // assume CSG_IteratorPtr is of the correct type.
        BSP_CSGMesh_FaceIt * face_it = (BSP_CSGMesh_FaceIt *)it;
 
-       if (face_it->pos < &(*face_it->mesh->FaceSet().end())) {
+       /* dereferencing iterator::end() is illegal, so we dereference 1 before it */
+       if (face_it->pos <= &(*(face_it->mesh->FaceSet().end() -1))) {
                if (face_it->face_triangle + 3 <= face_it->pos->m_verts.size()) {
                        return 0;
                }
@@ -253,8 +255,8 @@ BSP_CSGMesh_FaceIt_Step(
        // assume CSG_IteratorPtr is of the correct type.
        BSP_CSGMesh_FaceIt * face_it = (BSP_CSGMesh_FaceIt *)it;                
 
-       // safety guard
-       if (face_it->pos < &(*face_it->mesh->FaceSet().end())) {
+       /* dereferencing iterator::end() is illegal, so we dereference 1 before it */
+       if (face_it->pos <= &(*(face_it->mesh->FaceSet().end() -1))) {
 
                //if (face_it->face_triangle + 3 < face_it->pos->m_verts.size()) {
                //      (face_it->face_triangle)++;
index 07bcbf2b9d20aa0e14f9e89cb6f65089f472ce05..86b2fbaf4232b0fd20069a9cb68a67c3ddb1bfc5 100644 (file)
@@ -273,12 +273,13 @@ CollapseEdge(
        vector<LOD_EdgeInd>::iterator edge_it = degenerate_edges.begin();
        vector<LOD_EdgeInd>::const_iterator edge_end = degenerate_edges.end();
 
-       for (; edge_it != edge_end; ++edge_it) {
+       for (; !(edge_it == edge_end); ++edge_it) {
                        
-               LOD_Edge & edge = edges[*edge_it];
+               LOD_EdgeInd ed = (*edge_it);
+               LOD_Edge & edge = edges[ed];//*edge_it];
        
-               verts[edge.m_verts[0]].RemoveEdge(*edge_it);
-               verts[edge.m_verts[1]].RemoveEdge(*edge_it);
+               verts[edge.m_verts[0]].RemoveEdge(ed);
+               verts[edge.m_verts[1]].RemoveEdge(ed);
        }
 
        // we postpone deletion of the internal edges untill the end
index 16b80cdeea82f79fbfd356f7c81aeeaff5b96b78..a8328a9adbea5079702a152dc05bd7085fc14aa6 100644 (file)
@@ -62,11 +62,9 @@ RemoveEdge(
        if (result == m_edges.end()) {
                return false;
        }
-       LOD_EdgeInd last = m_edges.back();
-       m_edges.pop_back();
-       if (m_edges.empty()) return true;
 
-       *result = last;
+       std::swap(*result, m_edges.back());
+       m_edges.pop_back();
        return true;    
 };