Question

I'm seeing a crash when a sprite that has been assigned a path ends that path on 64-bit iOS devices and only when I move the sprite at the completion of the path.

Here's the stack trace(?).

enter image description here

And here's the code I'm using to create the path.

UIBezierPath *path1 = [[UIBezierPath alloc] init];

[path1 moveToPoint: CGPointMake(249, 430)];
[path1 addCurveToPoint: CGPointMake(154.7, 236.44) controlPoint1: CGPointMake(68.12, 359.17) controlPoint2: CGPointMake(117, 278.5)];
[path1 addCurveToPoint: CGPointMake(316, 127) controlPoint1: CGPointMake(192.41, 194.38) controlPoint2: CGPointMake(280.07, 195.64)];
[path1 addCurveToPoint: CGPointMake(249, -93) controlPoint1: CGPointMake(351.93, 58.36) controlPoint2: CGPointMake(327.18, -48.95)];

SKAction *firstPath = [SKAction followPath:[path1 CGPath] asOffset:NO orientToPath:NO duration:1.65];

When I run the code all I do is tell a sprite to run this action and when that completes -

This is the line of code that causes the crash.

[sprite runAction: [SKAction moveToPoint:CGPointMake(-100, -100)]];

I've tried turning on NSZombie and I'm not seeing anything from that. Additionally I've set the sprite to a strong property and still no difference.

Again this crash only occurs on 64bit iOS devices and not on 32bit devices.

Any suggestions on where to look for a solution to this?

Was it helpful?

Solution

From the UIBezierPath CGPath documentation:

The path object itself is owned by the UIBezierPath object and is valid only until you make further modifications to the path.

I assume by passing the path to Sprite Kit the action will eventually release the path, which it doesn't own, hence over-releasing it.

Try making a copy of the path:

SKAction *firstPath = [SKAction followPath:CGPathCreateCopy([path1 CGPath])
                                  asOffset:NO
                              orientToPath:NO
                                  duration:1.65];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top