4

I have been looking on this site and across google for about a week now trying to solve a bug in my app. It dosent look like memory management is the issue and breakpoints/instruments with zombies dosent return anything. All I have been able to figure out is that the issue stems from this block of code. When the app is run under certain circumstances it returns EXC_BAD_ACCESS on my main.m. I think this is the issue but thanks in advance for just looking over 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];
}

}

rcobelli
  • 199
  • 1
  • 2
  • 14
  • add an exception breakpoint and post any crash message printed to the log. Note that you leak the cgpath object, you have to cgpathrelease it. – CodeSmile Oct 01 '14 at 07:21
  • @LearnCocos2D I'll try the breakpoint exception when I get a chance later today but where would I cgpathrelease ? Thanks for the help! – rcobelli Oct 01 '14 at 11:12
  • After the lines.path = path; line. You still "own" the path so you have to release it. ARC doesn't automatically release core foundation objects like CGPath. – CodeSmile Oct 01 '14 at 12:25
  • @LearnCocos2D Hey, I tried both the breakpoint exception and adding CGPathRelease(path); but the crash and exception still occur. If you have any other ideas I would love to hear them but if not thanks for at least looking over it! – rcobelli Oct 01 '14 at 22:31
  • The exception breakpoint should show you the line of code closest to the error where source code is still available. Which line does Xcode highlight when it crashes? – CodeSmile Oct 02 '14 at 08:33
  • The exception breakpoint does absolutely nothing. It still crashes and highlights my main.m with error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x500000000000018)" Also there is nothing that is logged to console if that help you at all. – rcobelli Oct 03 '14 at 02:48
  • in that case it's harder to narrow it down. Your best bet is to remove parts of your project until the error goes away - in that case the error must be related to the most recently removed part. – CodeSmile Oct 03 '14 at 11:14
  • That was how I was originally able to narrow it down to this method within the code base. I am probably going to try to redo the whole system for drawing the line in a test project and copy over the code. Fingers crossed that it works but thanks anyways for the help! – rcobelli Oct 03 '14 at 15:05
  • I'm having similar problems, and there is a similar question posted [here](http://stackoverflow.com/q/26118928/1332415). From there you can follow a link trail of people reporting a similar problem after upgrading to iOS7.1. I'm not sure where the rabbit hole leads, but I know this: I can avoid all my crashes by recursively removing children from their parents before removing the parents. Try getting rid of your `SKAction` for removing from parent, and do something like [this](http://stackoverflow.com/a/23570896/1332415). Maybe a workaround until we can figure this out. – Karl Voskuil Oct 03 '14 at 15:29
  • Thank @KarlVoskuil While the solution that you suggested did not work (threw another EXC_BAD_ACCESS) I did notice that it was called over 200 times on the thread log before the app crashed. Do you know of a solution where I could keep this code block from updating as often? – rcobelli Oct 03 '14 at 23:31
  • @LearnCocos2D I started messing with it again and if I comment out the [lines runAction:[SKAction removeFromParent]]; line then it no longer crashes. I have no clue if this helps but once again thanks for the help! – rcobelli Oct 03 '14 at 23:48
  • @Appleguy1999, if you replace it with a simple `[lines removeFromParent]`, does it crash? I spent some time trying to figure out what it was about my so-called workaround that was working for me, and I think it's **just** the elimination of the `[SKAction removeFromParent]`. I'm getting good results from that kind of change. In fact, I think I might enter this as an answer, because it's working for me. – Karl Voskuil Oct 04 '14 at 01:20

1 Answers1

3

I'm having the same problem, with the same symptoms: The code worked in iOS7.1 but started crashing with EXC_BAD_ACCESS in iOS8; trying to trace the source of the bad access with zombies doesn't help.

Here's what's working for me to fix the problem: Eliminate all uses of [SKAction removeFromParent].

For your example, that would just mean replacing [lines runAction:[SKAction removeFromParent]] with [lines removeFromParent].

A little trickier is replacing 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 right search terms, I found a link to another question describing the same problem.

Community
  • 1
  • 1
Karl Voskuil
  • 750
  • 6
  • 19
  • Thanks! This was a life saver and I was finally able to stop the timer for work on this one bug at many, many hours. Once again, Thanks! – rcobelli Oct 04 '14 at 02:24