views:

25

answers:

1

Yeah, so this one through me or a loop for a while until I figured out what was going on. With Apple releasing the final version of Xcode today, and iOS 4 coming out yesterday, I finally started to look into porting my apps to iOS 4.

So I downloaded the new SDK, and got to work. After working on my app a bit, imagine my surprise when I got a bad access error, (trying to talk to a deallocated object). I hate those errors, so hard to figure out what to do. So, I spent the last 45 minutes trying to find what object I had deallocated. I couldn't recall what I had changed, and the error messages weren't helping. I enabled NSZombies (Zombies!!!) and got this error:

2010-06-22 15:38:28.655 ProjectPidgey[17783:207] *** -[CCTargetedTouchHandler claimedTouches]: message sent to deallocated instance 0xd834b30

Which is about as useful as it seems. I'm in Cocos2D, so I think something is being touched that no longer exists? But I couldn't find anything like that in my code. So, on a whim, I used my older version of Xcode. Compiled and installed it on the Simulator running iOS 3.0. Worked fine. Like a charm, just as I had made it.

So now, my question is, what's happening here. What is the difference between SDK 4 and 3 that would cause a Bad Exc Error? Any ideas? Or perhaps it's an issue with cocos2d and that needs to be updated?

Edit: I did some messing around and found that by removing this line of code:

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchPoint = [touch locationInView:[touch view]];
    touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
    if ( ![super containsTouchLocation:touch] ) return NO;
    [self.engine playerHitRedDot:self];
    //[self.parent removeChild:self cleanup:YES]; //REMOVED THIS LINE
    return YES;
}

Then it works. So it looks like the CCTargedTouch Handler is linked to my sprite (which is then removed when I touch it) and someone everything doesn't work out... However, I need the sprites to get removed (or at least disappear, but I want to be memory conscientious), so how can I do this?

Thanks!

+1  A: 
2010-06-22 15:38:28.655 ProjectPidgey[17783:207] *** -[CCTargetedTouchHandler claimedTouches]: message sent to deallocated instance 0xd834b30

That is very useful. It is telling you exactly what went wrong; an over-released instance of CCTargetedTouchHandler had a method invoked upon it.

Every Cocos2d based project has the full source embedded and if you are using Instruments to track the Zombies, you can see the exact backtrace of where the object was created, retained and/or released.

It might be a bug in Cocos2d, but I doubt it reading the code. This looks more like it is an over-release in your application that happened to not trigger a crash before, but does now. Either something isn't retained that should be, something isn't nild out that should be and/or you are passing stuff between threads in an unsafe fashion.

bbum
I'll mark this as an answer, but as it helped me in the debugging, but I never found the actual bug. I used NSZombies in Instruments and everything possible to track down the bug, but eventually left it as that, a bug. And did a small hack to get around it (doing one thing on OS 4, but a different thing on OS 3). It works, but I wish there was a better solution...
Wayfarer