Open LearnCocos2D opened 9 years ago
In one particular crash the thread stopped at the last line in this code fragment:
void internalDecomposePoly(const Verticies &inputPoly, VerticiesList & outputPolys)
{
CGPoint upperInt, lowerInt, p, closestVert;
Scalar upperDist, lowerDist, d, closestDist;
int upperIndex, lowerIndex, closestIndex;
Verticies lowerPoly, upperPoly;
for (int i = 0; i < inputPoly.size(); ++i) {
if (isReflex(inputPoly, i)) {
upperDist = lowerDist = numeric_limits<Scalar>::max();
for (int j = 0; j < inputPoly.size(); ++j) {
if (left(at(inputPoly, i - 1), at(inputPoly, i), at(inputPoly, j))
&& rightOn(at(inputPoly, i - 1), at(inputPoly, i), at(inputPoly, j - 1))) { // if line intersects with an edge
This is a dump of the local variables at the time, the inputPoly buffer seems to be maxed out (32767 size):
inputPoly const Verticies & size=32767 0x00007fff5fbe8da8
p CGPoint (x=12.103944885733787, y=11.896055114266213)
j int 12776 12776
upperDist Scalar 1.7976931348623157E+308 1.7976931348623157E+308
lowerDist Scalar 1.7976931348623157E+308 1.7976931348623157E+308
i int 226 226
upperPoly Verticies size=0
lowerPoly Verticies size=0
From time to time when editing physics shapes SpriteBuilder freezes. This happens when inserting a new vertex. Based on the call stack it freezes inside the method that decomposes the polygon into convex polygons. Xcode typically shows me some code of the C++ std::vector class.
Call stack:
This is what I was editing at the time (trying to reproduce the issue hence the somewhat odd shape), with the last vertex added when the freeze occured highlighted in red:
The freeze occurs in debug builds of SpriteBuilder.
It appears I can reproduce it only one in 10 times. When it occurs I can usually reproduce it 2-3 times by trying to retrace the same shape in the same way. Thus far I've only encountered the freeze in more complex shapes, ie 8+ vertices.
But if you just start creating a legal shape and keep adding vertices to it, eventually the freeze will occur almost inevitably. The more concave the shape the better, as it'll give the decomposing function more work to do which seems to increase the likelihood of the issue occuring.