From 1cc2564c53f26b1e130a970dfffe13334752a08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 May 2020 12:11:03 +0200 Subject: [PATCH] MeshTools: properly reduce unique prefix in the last iteration. The test passes now. --- src/Magnum/MeshTools/RemoveDuplicates.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Magnum/MeshTools/RemoveDuplicates.h b/src/Magnum/MeshTools/RemoveDuplicates.h index ceb770c4b..8a7e6fffe 100644 --- a/src/Magnum/MeshTools/RemoveDuplicates.h +++ b/src/Magnum/MeshTools/RemoveDuplicates.h @@ -283,15 +283,15 @@ template std::size_t removeDuplicatesFuzzyIndexed /* Remap the resulting index array */ for(auto& i: indices) i = remapping[i]; - /* Finished */ - if(moving == Vector::Size) continue; - - /* Move vertex coordinates by epsilon/2 in the next direction */ - moved = Vector(); - moved[moving] = epsilon/2; + /* Move vertex coordinates by epsilon/2 in the next direction. Do that + only if we're not in the last iteration, as that would be an OOB + access otherwise. */ + if(moving != Vector::Size) { + moved = Vector(); + moved[moving] = epsilon/2; + } - /* Next time go only through the unique prefix; clear the table for the - next pass */ + /* Reduce to an unique prefix; clear the table for the next pass */ dataSize = table.size(); table.clear(); }