spritebuilder / SpriteBuilder

Objective-C Game Development Suite
http://www.spritebuilder.com/
Other
741 stars 293 forks source link

Physics shape editing occasionally freezes SpriteBuilder (SIGSTOP) #1045

Open LearnCocos2D opened 9 years ago

LearnCocos2D commented 9 years ago

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:

Thread 1Queue : com.apple.main-thread (serial)
#0  0x000000010001b3d8 in std::__1::__vector_base<CGPoint, std::__1::allocator<CGPoint> >::__alloc() [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:354
#1  0x000000010001b3d8 in std::__1::__vector_base<CGPoint, std::__1::allocator<CGPoint> >::__destruct_at_end(CGPoint*) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:448
#2  0x000000010001b3b4 in std::__1::__vector_base<CGPoint, std::__1::allocator<CGPoint> >::clear() [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:372
#3  0x000000010001b39e in std::__1::__vector_base<CGPoint, std::__1::allocator<CGPoint> >::~__vector_base() at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:475
#4  0x000000010001bb05 in std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >::~vector() at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:481
#5  0x00000001000189c5 in std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >::~vector() at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:481
#6  0x0000000100014552 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:259
#7  0x00000001000180c6 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:339
#8  0x0000000100018079 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:335
#9  0x0000000100018091 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:336
#10 0x00000001000180c6 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:339
#11 0x0000000100018091 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:336
#12 0x00000001000180c6 in internalDecomposePoly(std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > const&, std::__1::vector<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> >, std::__1::allocator<std::__1::vector<CGPoint, std::__1::allocator<CGPoint> > > >&) at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:339
#13 0x000000010001329d in +[PolyDecomposition bayazitDecomposition:outputPoly:] at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PolyDecomposition.mm:144
#14 0x00000001001601c9 in -[PhysicsHandler renderPhysicsBody:editorView:] at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PhysicsHandler.m:770
#15 0x0000000100162173 in -[PhysicsHandler updatePhysicsEditor:] at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/PhysicsHandler.m:954
#16 0x000000010005c90e in -[CocosScene update:] at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/CocosScene.m:2195
#17 0x00000001002eb27d in InvokeMethods at /depot-koboldkit/SpriteBuilder/SpriteBuilder/libs/cocos2d-iphone/cocos2d/CCScheduler.m:89
#18 0x00000001002ec8c0 in -[CCScheduler update:] at /depot-koboldkit/SpriteBuilder/SpriteBuilder/libs/cocos2d-iphone/cocos2d/CCScheduler.m:519
#19 0x00000001002e13a7 in -[CCDirector drawScene] at /depot-koboldkit/SpriteBuilder/SpriteBuilder/libs/cocos2d-iphone/cocos2d/CCDirector.m:235
#20 0x00007fff87dcb7ce in __NSThreadPerformPerform ()
#21 0x00007fff928545b1 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#22 0x00007fff92845c62 in __CFRunLoopDoSources0 ()
#23 0x00007fff928453ef in __CFRunLoopRun ()
#24 0x00007fff92844e75 in CFRunLoopRunSpecific ()
#25 0x00007fff93487a0d in RunCurrentEventLoopInMode ()
#26 0x00007fff934877b7 in ReceiveNextEventCommon ()
#27 0x00007fff934875bc in _BlockUntilNextEventMatchingListInModeWithFilter ()
#28 0x00007fff91b6224e in _DPSNextEvent ()
#29 0x00007fff91b6189b in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#30 0x00007fff91b5599c in -[NSApplication run] ()
#31 0x00007fff91b40783 in NSApplicationMain ()
#32 0x0000000100022392 in main at /depot-koboldkit/SpriteBuilder/SpriteBuilder/ccBuilder/main.m:9
#33 0x00007fff946ac5fd in start ()

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:

screen shot 2014-10-22 at 17 26 21

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.

LearnCocos2D commented 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