EXC_BAD_ACCESS Sprite Kit

I searched this site and through google for about a week trying to solve a problem with my application. This docent looks like memory management - it's a problem and checkpoints / tools with the addition of a zombie dispenser. All I was able to figure out is that the problem is with this block of code. When the app is launched under certain circumstances, it returns EXC_BAD_ACCESS on my main.m. I think this is a problem, but ahead of time for just looking at it!

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if (!gameOver && gameStarted) {

[lines runAction:[SKAction removeFromParent]];
dotDrawn = NO;

UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];

pos2x = positionInScene.x;
pos2y = positionInScene.y;

lines = [SKShapeNode node];

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, pos1x, pos1y);
CGPathAddLineToPoint(path, NULL, pos2x, pos2y);

lines.path = path;
lines.strokeColor = [UIColor grayColor];
[lines setLineWidth:3];

[self addChild:lines];
}

      

}

+3


source to share


1 answer


I have the same problem, with the same symptoms: the code worked in iOS7.1 but started crashing with EXC_BAD_ACCESS in iOS8; trying to track down the source of the bad access with a zombie doesn't help.

Here's what works for me to fix the problem: Exclude all uses [SKAction removeFromParent]

.

In your example, that would mean replacing [lines runAction:[SKAction removeFromParent]]

with [lines removeFromParent]

.

It's a little harder to replace with something like this:



[myNode runAction:[SKAction sequence:@[ [SKAction fadeOutWithDuration:1.0],
                                        [SKAction removeFromParent] ]]];

      

with this:

[myNode runAction:[SKAction fadeOutWithDuration:1.0] completion:^{
    [myNode removeFromParent];
}];

      

Edit: Using the correct search terms, I found a link to another question describing the same problem .

+3


source







All Articles