0

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!

4

1 回答 1

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

这是非常有用的。它准确地告诉您出了什么问题;一个过度释放的实例CCTargetedTouchHandler有一个对其调用的方法。

每个基于 Cocos2d 的项目都嵌入了完整的源代码,如果您使用 Instruments 跟踪 Zombies,您可以看到创建、保留和/或释放对象的确切回溯。

这可能是 Cocos2d 中的一个错误,但我怀疑它阅读代码。这看起来更像是您的应用程序中的过度释放,之前碰巧没有触发崩溃,但现在却触发了。要么没有保留应该保留的东西,没有保留应该保留的东西nil和/或你正在以不安全的方式在线程之间传递东西。

于 2010-06-23T04:32:52.740 回答