Surface_mesh: Fix collect_garbage in case mesh is not valid

This commit is contained in:
Andreas Fabri 2025-09-26 12:09:13 +01:00
parent 23e624b0e8
commit 4176a2a551
2 changed files with 34 additions and 3 deletions

View File

@ -2680,8 +2680,12 @@ collect_garbage(Visitor &visitor)
for (i=0; i<nH; ++i)
{
h = Halfedge_index(i);
set_target(h, vmap[target(h)]);
set_next(h, hmap[next(h)]);
if(target(h) != null_vertex()){
set_target(h, vmap[target(h)]);
}
if(next(h) != null_halfedge()){
set_next(h, hmap[next(h)]);
}
if (!is_border(h))
set_face(h, fmap[face(h)]);
}
@ -2691,7 +2695,8 @@ collect_garbage(Visitor &visitor)
for (i=0; i<nF; ++i)
{
f = Face_index(i);
set_halfedge(f, hmap[halfedge(f)]);
if( halfedge(f) != null_halfedge())
set_halfedge(f, hmap[halfedge(f)]);
}
//apply visitor before invalidating the maps

View File

@ -0,0 +1,26 @@
#include <CGAL/Surface_mesh/Surface_mesh.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick;
int main()
{
CGAL::Surface_mesh<CGAL::Epick::Point_3> mesh;
auto f0 = mesh.add_face();
auto f1 = mesh.add_face(); // If this line is commented out, it will not crash.
mesh.remove_face(f0);
auto v0 = mesh.add_vertex();
auto v1 = mesh.add_vertex(); // If this line is commented out, it will not crash.
mesh.remove_vertex(v0);
auto e0 = mesh.add_edge();
auto e1 = mesh.add_edge(); // If this line is commented out, it will not crash.
mesh.remove_edge(edge(e0,mesh));
mesh.collect_garbage();
return 0;
}