Comments (11)
I'll look into the issue, some vertex data to reproduce the crash would be perfect.
This is likely related to mapbox/earcut#87
from earcut.hpp.
Earcut::filterPoints may return nullptr in case it reduces the polygon into a point
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
from earcut.hpp.
Earcut::filterPoints may return nullptr in case it reduces the polygon into a point
Note that it can never return null — in the case of a point, it will return the pointer to that point's node. So the cause must be something else.
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?
if (!p->steiner && (equals(p, p->next) || area(p->prev, p, p->next) == 0)) {
removeNode(p);
p = end = p->prev;
if (p == p->next) return nullptr;
again = true;
} else {
p = p->next;
}
from earcut.hpp.
I'll look into the issue, some vertex data to reproduce the crash would be perfect.
This is likely related to mapbox/earcut#87
Looks like the same issue, I agree!
Below is one example polygon which causes the issue:
0:
-32, 493
-32, 444
0, 440
6, 487
1:
-32, 501
-13, 645
-32, 648
2:
-32, 493
-32, 444
0, 440
6, 487
3:
-32, 501
-13, 645
-32, 648
4:
-32, 493
-32, 444
0, 440
6, 487
5:
-32, 501
-13, 645
-32, 648
6:
-32, 493
-32, 444
0, 440
6, 487
7:
-32, 501
-13, 645
-32, 648
8:
-32, 493
-32, 444
0, 440
6, 487
9:
-32, 501
-13, 645
-32, 648
10:
-32, 493
-32, 444
0, 440
6, 487
11:
-32, 501
-13, 645
-32, 648
from earcut.hpp.
@huhtanen yeah my bad, I missed this line https://github.com/mapbox/earcut.hpp/blob/master/include/mapbox/earcut.hpp#L235
from earcut.hpp.
replacing return nullptr;
with break;
(or the equivalent return p;
) should do the trick, but it's probably better to check the changes with a larger test set than we have hardcoded here.
from earcut.hpp.
replacing return nullptr; with break; (or the equivalent return p;) should do the trick, but it's probably better to check the changes with a larger test set than we have hardcoded here.
In that case should the below nullptr check be if (ear == ear->next)
, or should it simply be removed?
template <typename N>
void Earcut<N>::earcutLinked(Node* ear, int pass) {
if (!ear) return;
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.
from earcut.hpp.
@huhtanen Neither. earcutLinked
will not do anything if ear == ear->next
anyway. But checking for a nullptr is required for code sanity reasons, even if it might never happen.
from earcut.hpp.
@mrgreywater are you looking into a fix? I guess always treating 1-point holes as if they were Steiner points (and never returning null
in filterPoints
) seems like a good solution.
from earcut.hpp.
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.
from earcut.hpp.
So I rewrote the tests to be auto registering, which allows custom (manually written) tests without risking them to be overwritten by the script.
Interestingly after I added the patch, the new test case also gave out some new undefined behaviour warnings which we will have to look into.
/home/travis/build/mrgreywater/earcut.hpp/include/mapbox/earcut.hpp:606:60: runtime error: division by zero
/home/travis/build/mrgreywater/earcut.hpp/include/mapbox/earcut.hpp:606:38: runtime error: value -nan is outside the range of representable values of type 'int'
/home/travis/build/mrgreywater/earcut.hpp/include/mapbox/earcut.hpp:607:60: runtime error: division by zero
/home/travis/build/mrgreywater/earcut.hpp/include/mapbox/earcut.hpp:607:38: runtime error: value -nan is outside the range of representable values of type 'int'
/home/travis/build/mrgreywater/earcut.hpp/include/mapbox/earcut.hpp:609:17: runtime error: left shift of negative value -2147483648
/home/travis/build/mrgreywater/earcut.hpp/include/mapbox/earcut.hpp:614:17: runtime error: left shift of negative value -2147483648
from earcut.hpp.
Related Issues (20)
- 'cut' introduced in complex polygon HOT 1
- New test “issue142” in 2.2.4 fails on aarch64, ppc64le, s390x HOT 1
- Member function of Earcut Assumes that the point type has a size member function HOT 5
- Helper function for earcutting just a std::vector<> of points HOT 1
- Incorrect Triangulation HOT 1
- missing triangle HOT 2
- Builds wrong indices array for concave polygon HOT 2
- The Ear Point judgment HOT 2
- Coverity scan fails HOT 1
- Transfer Appveyor project to Mapbox? HOT 4
- Clang-Tidy static analysis warning: dereference of a null pointer HOT 2
- Issues with triangulating a polygon with 3d coords HOT 1
- How to clip with an outside polygon HOT 1
- Infinite loop in cureLocalIntersections HOT 2
- When I use Clipper to cut polygons, sometimes I get some separated polygons and some holes. How can I use earcut to process these separated polygons? HOT 8
- Endless loop in the filterPoints function HOT 1
- Any way to make this use even-odd rule? HOT 1
- Port infinite loop fix HOT 1
- Please consider adding a version tag on commit 6d18edf0ce046023a7cb55e69c4cd9ba90e2c716 or later HOT 4
- Test “self_touching” fails on aarch64, ppc64le, s390x HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from earcut.hpp.