SKShapeNode with path causing crashing.

I am using a SpriteKit layer as a HUD. The layer include 2d sprite elements, and I need a couple of procedural line-draws.

This means each tick replacing the SKShapeNode's path with a new one. Which I am building with CGMutablePath


This works for about 10 seconds, and then there's a crash. (EXC_BAD_ACCESS) Usually the debugger shows Main/ApplicationDelegate

But digging around in the stack reveals it is something going on in the line draw.


let relTrail:[CGPoint] = [CGPoint(0,0),CGPoint(0,-10),CGPoint(-10,-20)]         /
let startPt = relTrail[0]
let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, startPt.x, startPt.y)
for pt in relTrail
{
    CGPathAddLineToPoint(path , nil , pt.x , pt.y)
}
self.shapeNode.path = path


Looking at the documention it feels like SKShapeNode supports path drawing, but does not expect the path to be dynamically changed once per frame.


Are there, perhaps some other ways to accomplish the same goal?

Replies

> but does not expect the path to be dynamically changed once per frame.


It can be changed once per frame. I have a very similar code which works OK on each update of the scene. So I guess you are in the right direction and the bug is not connected to SKShapeNode.

I am updating the path in the scene update. This works, but crashes with a memory issue after perhaps 100-200 frames. It clearly is related to SKShapeNode. I can establish this because of a) stack traces , b) commenting out the code.


It could be a new iOS 10 issue.


But for the time being, I solved the problem by shoving all line-drawing into a conventional UIView layer. I did attempt to draw directly into the SKView, but drawRect is never called.

I did not test my app on ios10 yet. If it does work on ios9 and crashes on ios10 please create a ticket.