-
Notifications
You must be signed in to change notification settings - Fork 131
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
Crash in Earcut::findHoleBridge #54
Comments
I'll look into the issue, some vertex data to reproduce the crash would be perfect. This is likely related to mapbox/earcut#87 |
Note that it should never return null — in the case of a point, it will return the pointer to that point's node. Also looks related to mapbox/earcut#83 |
Not sure what you mean. As far as I understand it, the code from filterPoints below checks whether the current edge is degenerate, or the two adjacent edges are colinear, and in such case removes the middle node. After this elimination it checks if the current node is same node as next node, and returns nullptr; If p == p->next, then isn't the polygon just a point?
|
Looks like the same issue, I agree! Below is one example polygon which causes the issue:
|
@huhtanen yeah my bad, I missed this line https://github.com/mapbox/earcut.hpp/blob/master/include/mapbox/earcut.hpp#L235 |
replacing |
In that case should the below nullptr check be
eliminateHoles could also early exit by checking every iteration if p == p->next, instead for p == nullptr, but then again, it might not be common enough case to warrant for extra checks. |
@huhtanen Neither. |
@mrgreywater are you looking into a fix? I guess always treating 1-point holes as if they were Steiner points (and never returning |
I am, but I want to rewrite the test generating script first, to allow additional tests for earcut.hpp that aren't in earcut.js. I don't want to merge the fix without having a testcase that actually confirms it's working. |
So I rewrote the tests to be auto registering, which allows custom (manually written) tests without risking them to be overwritten by the script.
|
Hi,
Earcut::eliminateHoles contains the following loop:
Earcut::filterPoints may return nullptr in case it reduces the polygon into a point, but findHoleBridge called by eliminateHole expects outerNode to be non-null, and crashes if filterPoints returns nullptr before the last iteration of the above for-loop on this line:
if (hy <= p->y && hy >= p->next->y && p->next->y != p->y) {
I've locally fixed/worked around the issue by modifying the loop condition in eliminateHoles as follows:
and made similar modification to call-site of eliminateHoles to handle the nullptr case.
Is this the correct way around the issue?
The text was updated successfully, but these errors were encountered: