views:

70

answers:

1

Hi all im getting a EXC_BAD_ACCESS error on this line.

[(CCMenuItemSprite*)[profileSelectionMenu getChildByTag:333] setNormalImage:normalSprite3];

Basically im just trying to change the normal image of a CCMenuItemSprite. normalSprite3 and selectedSprte3 are both CCSprite. and i set the properties off them to retain but it still always crashing on the above line. Is there an easier way to do what im trying to accomplish? basically set the button to be a toggle button? and it changes image everytime it is pressed

normalSprite3 =[CCSprite spriteWithFile:@"main_menu_button.png"];
selectedSprite3 =[CCSprite spriteWithFile:@"main_menu_button_select.png"];



profile3MenuItem = [CCMenuItemImage itemFromNormalSprite:normalSprite3 selectedSprite:selectedSprite3
                                                          target:self
                                                        selector:@selector(P3:)];
        [profile3MenuItem setTag:333];

[(CCMenuItemSprite*)[profileSelectionMenu getChildByTag:333] setNormalImage:normalSprite3];

Thanks for any help G

A: 

Why not just

[profile3MenuItem setNormalImage:normalSprite3];

Also, where do you add the item to profileSelectionMenu so that getChildByTag works?

UPDATE: I wrote this to help with debugging EXC_BAD_ACCESS

http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html

If you think you are releasing early, turn on NSZombiesEnabled

http://loufranco.com/blog/files/debugging-memory-iphone.html

Lou Franco
profileSelectionMenu = [CCMenu menuWithItems:profile1MenuItem,profile2MenuItem,profile3MenuItem,profile4MenuItem,profile5MenuItem, nil]; is the line where i add the menu item to the menu. yeah i had tried what u suggested too with same result. They both work if i have them in the same initialise function but when i use the line in the function called P3 it crashes. so some thing has to be deallocated somewhere but i cant see how while i have been using retain.
Udpated with help finding deallocated objects (use NSZombiesEnabled)
Lou Franco
that was exactly it i wasnt aware of NSZombiesEnabled and the others in ur links. One of my sprites was being dealloc early which i figured but i was ale to narrow down and fix the problem thank you soo much for that!cheers G