views:

132

answers:

1

Hi,

So I'm getting a EXC_BAD_ACCESS error in cocos2d. From what I've been searching so far it's mostly related to attempting to free an object which has already been released. I have encountered this error before, and its solution was simple and pretty much caused by freeing a released object. But now, using cocos2d (not sure if it's a bug in their framework or not), I'm getting an EXC_BAD_ACCESS in this line:

CCMenuItemSprite *btn = [CCMenuItemSprite itemFromNormalSprite:op selectedSprite:op target:self selector:NSSelectorFromString([sceneMethods objectAtIndex:i])];

Basically, I'm creating a simple menu system for easy maintenance and updating. Nothing too serious. In this particular line, I'm creating a CCMenuItemSprite with self as target and using a selector. I've already asserted that the selector passed as argument is correct and also tried to use different for the normal and selected sprite (though that shouldn't make any difference) but still no go! The error is deep in the cocos2d framework, precisely when the CCMenuItem is "activated" which calls invoke on a NSInvoker of that same class. And analyzing the stack trace, it crashes exactly on the invoke method, which leads to believe it has something to do with the NSInvoker. Anyone had a similar problem or have a suggestion for this problem? Thanks in advance.

A: 

Just a guess: are you completely sure that all of the objects in sceneMethods are real selectors?

JeremyP
yes, they are. Well not selectors, NSStrings from selectors but I already asserted that:NSLog(@"%@", NSStringFromSelector(NSSelectorFromString([sceneMethods objectAtIndex:i])));
Ricardo Ferreira
Yes, sorry, I meant string representations of selectors. That means `op` must be bad somehow.
JeremyP
Well what op is, is basically a CCSprite*, but if it was bad it would not break the program where it currently breaks, actually it should throw an exception if they were nil, and it retains internally the reference of those sprites. I'm really clueless, I've already printed the whole array but it seems okay. The stack trace leads me to the internal cocos2d framework, that's why I thought it was a bug...
Ricardo Ferreira