diff --git a/src/OpenMesh/Tools/Decimater/McDecimaterT.cc b/src/OpenMesh/Tools/Decimater/McDecimaterT.cc index f974753f..8dcfe74b 100644 --- a/src/OpenMesh/Tools/Decimater/McDecimaterT.cc +++ b/src/OpenMesh/Tools/Decimater/McDecimaterT.cc @@ -141,6 +141,11 @@ size_t McDecimaterT::decimate(size_t _n_collapses) { tmpHandle = typename Mesh::HalfedgeHandle( (double(rand()) / double(RAND_MAX) ) * double(mesh_.n_halfedges()-1) ); #endif + // Only take valid Handles! + if ( tmpHandle.idx() >=mesh_.n_halfedges() ) { + continue; + } + // if it is not deleted, we analyse it if ( ! mesh_.status(tmpHandle).deleted() ) { @@ -263,6 +268,11 @@ size_t McDecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { tmpHandle = typename Mesh::HalfedgeHandle( ( double(rand()) / double(RAND_MAX) ) * double(mesh_.n_halfedges() - 1)); #endif + // Only take valid Handles! + if ( tmpHandle.idx() >=mesh_.n_halfedges() ) { + continue; + } + // if it is not deleted, we analyse it if (!mesh_.status(tmpHandle).deleted()) { @@ -401,6 +411,11 @@ size_t McDecimaterT::decimate_constraints_only(float _factor) { tmpHandle = typename Mesh::HalfedgeHandle(int(rand() * randomNormalizer ) ); #endif + // Only take valid Handles! + if ( tmpHandle.idx() >=mesh_.n_halfedges() ) { + continue; + } + // if it is not deleted, we analyze it if (!mesh_.status(mesh_.edge_handle(tmpHandle)).deleted()) {