artem-ogre/CDT

insertEdgeIteration will crash if iTopo value is 'noNeighbor'

proc-sim opened this issue · 5 comments

Ran into a case where insertEdgeIteration can generate an unhandled exception. Line 524 of Triangulation.hpp can return a value of 'noNeighbor' which is then used (without a bounds check) to access an array by index - instant crash.

itopo

Do you have an example of code and input to reproduce the issue?

Sure, here's the code:

CDT::Triangulation<double> cdt;
cdt.insertVertices(cdtVerts); 
cdt.insertEdges(cdtEdges);  
cdt.eraseOuterTrianglesAndHoles();

And attached are the contents of the cdtVerts and cdtEdges arrays, in the format:

vert1x
vert1y
vert2x
vert2y
....

and

edge1v1
edge1v2
edge2v1
edge2v2
....

You should be able to read the values in line-by-line to fill the arrays.

cdtDebugEdges.txt
cdtDebugVerts.txt

Hi @Tysoni
Thanks for opening the issue. CDT does not support duplicated (exactly) vertices and intersecting edges (can be automatically resolved with IntersectingConstraintEdges::Resolve but without guaranties).

The input you provided has duplicates. FindDuplicates returns:

duplicates = 
 [0] = 428
 [1] = 429
 [2] = 430
 [3] = 431
 [4] = 432
 [5] = 433
 [6] = 434
 [7] = 435

After fixing it with CDT::RemoveDuplicates and using CDT::IntersectingConstraintEdges::Resolve triangulation finishes successfully.
cdt_screenshot

I'm closing this, please let me know if you think this should be re-open.

Thanks @artem-ogre. I had pre-processed my polygons to remove duplicate verts that are next to each other...but wasn't aware that duplications anywhere in the polygon - even across non-adjacent edges - were a problem. Will make sure to avoid that in the future. I appreciate you taking the time to investigate this!