-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
triangulator memory corruption #162
Comments
It seems that Edit: we got a cycle in index d0affe3..c266358 100644
--- a/src/polygon/src/polygon.cpp
+++ b/src/polygon/src/polygon.cpp
@@ -88,10 +88,16 @@ class Monotones {
if (precision_ < 0) precision_ = bound * kTolerance;
- if (SweepForward()) return;
+ if (SweepForward()) {
+ std::cout << "sweepforward return" << std::endl;
+ return;
+ }
Check();
- if (SweepBack()) return;
+ if (SweepBack()) {
+ std::cout << "sweepback return" << std::endl;
+ return;
+ }
Check();
}
@@ -141,6 +147,27 @@ class Monotones {
// A variety of sanity checks on the data structure. Expensive checks are only
// performed if params.intermediateChecks = true.
void Check() {
+ std::vector<PairItr> pairs;
+ for (PairItr pair = activePairs_.begin(); pair != activePairs_.end(); pair++) {
+ if (std::find(pairs.begin(), pairs.end(), pair) != pairs.end()) {
+ std::cerr << "cycle" << std::endl;
+ abort();
+ }
+ pairs.push_back(pair);
+ }
+ unsigned int num = pairs.size();
+ for (PairItr pair = inactivePairs_.begin(); pair != inactivePairs_.end(); pair++) {
+ auto iter = std::find(pairs.begin(), pairs.end(), pair);
+ if (iter != pairs.end()) {
+ if (std::distance(pairs.begin(), iter) >= num)
+ std::cerr << "inactivePairs_ cycle" << std::endl;
+ else
+ std::cerr << "duplicate" << std::endl;
+ abort();
+ }
+ pairs.push_back(pair);
+ }
+
if (!params.intermediateChecks) return;
std::vector<Halfedge> edges;
for (VertItr vert = monotones_.begin(); vert != monotones_.end(); vert++) {
@@ -914,7 +941,9 @@ std::vector<glm::ivec3> Triangulate(const Polygons &polys, float precision) {
std::vector<glm::ivec3> triangles;
try {
Monotones monotones(polys, precision);
+ monotones.Check();
monotones.Triangulate(triangles);
+ monotones.Check();
if (params.intermediateChecks) {
CheckTopology(triangles, polys);
CheckGeometry(triangles, polys, precision); It seems that the cycle is formed after failed sweep back (return non-zero in sweep back). |
Thanks for the analysis! I should be able to use that to spit out a test case polygon. Good sleuthing! |
I got address sanitizer working, but your patch isn't printing anything for me. Is there anything else required to repro? Also, if you replace |
Did you change the max iteration to 10? The current one in master will not trigger the error. |
Indeed I did; it fails, but on the |
Weird, or maybe the cycle is formed due to memory corruption and compiling this with different options somehow changed the behavior? No idea. |
Okay, I managed to dump out the polygon and create a simple repro test. |
This tracks the bug mentioned in #160
I managed to reproduce this with address sanitizer enabled, giving some useful backtrace:
The text was updated successfully, but these errors were encountered: