Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:54:03+00:00 2026-06-15T14:54:03+00:00

I always used ARC but my cocos2d template doesn’t use ARC, to I have

  • 0

I always used ARC but my cocos2d template doesn’t use ARC, to I have to use the manual ref counting and that’s probably why I crash.
The goal is to make a menu with two labels, if I click to a label, I show an image with a sprite.If I click on the image, I can go back to the menu and choose again.
This is the CCLayer class:

-(id) init
{
    if( (self=[super init]))
    {
        CCMenuItemLabel* item1, *item2;
        CCLabelTTF* label1= [CCLabelTTF labelWithString: @"Shark Icon" fontName: @"Arial" fontSize: 30], *label2;
        label2= [CCLabelTTF labelWithString: @"Cocos2D Icon" fontName: @"Arial" fontSize: 30];
        label1.color=  ccRED;
        label2.color= ccRED;
        [label1 retain];
        [label2 retain];
        item1=[CCMenuItemLabel itemWithLabel: label1 block:^(id sender)
        {
            NSLog(@"Clicked shark icon");
            [self removeChild: menu cleanup: NO];
            shark=[CCSprite spriteWithFile: @"shark.jpeg"];
            [shark setPosition: CGPointMake(150, 200)];
            [self addChild: shark];
            [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate: self priority: 0 swallowsTouches: YES];
        }];
        item2= [CCMenuItemLabel itemWithLabel: label2 block:^(id sender)
        {
            NSLog(@"Clicked cocos2d icon");
            [self removeChild: menu cleanup: NO];
            icon=[CCSprite spriteWithFile: @"icon.png"];
            [icon setPosition: CGPointMake(150, 200)];
            [self addChild: icon];
            [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate: self priority: 0 swallowsTouches: YES];
        }];
        [item1 retain];
        [item2 retain];
        menu=[CCMenu menuWithItems: item1,item2, nil];
        [menu alignItemsVertically];
        [self addChild: menu];
    }
    return self;
}

- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    [[CCTouchDispatcher sharedDispatcher] removeDelegate: self];
    [self removeChild: shark cleanup: NO];
    [self addChild: menu];
    return YES;
}

What happens: I click on “Shark Icon” (or “Cocos2D Icon”), then the shark image appears,if I click on it I get EXC_BAD_ACCESS:

EXC_BAD_ACCESS (code=1, address= 0x70Baafc8)

I tried to print all addresses (menu, item1,etc…), and no one of the items has this address.Sometimes I even get an invalid address like 0x00000008 .

EDIT

I would solve the problem by just retaining menu, but I haven’t understood why: menu is already retained:

@property (nonatomic, retain) CCSprite* shark;
@property (nonatomic, retain) CCSprite* icon;
@property (nonatomic, retain) CCMenu* menu;

If I enable zombies I get this:

*** -[CCMenu tag]: message sent to deallocated instance 0x7c71a10

So menu is a zombie but shouldn’t the retain property make it be retained?
The strange thing is that I don’t need to retain shark and icon, just menu.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:54:04+00:00Added an answer on June 15, 2026 at 2:54 pm
    menu = [CCMenu menuWithItems: item1,item2, nil]; 
    

    menu was never retained. if its a retain property use self.menu

    you create a new shark every time but want to reuse your menu!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have always used Authlogic in Rails 2.3 but now that I am using
I have always used the mouseover event, but while reading the jQuery documentation I
I have always used TurtoiseSVN but this time I want to checkout code from
I always used to use Dreamweaver for web work, but now I work in
I have always used winforms to do my projects but I have never really
I have always used: serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); which means that I will accept connections
i have seen that ajaxStart/ajaxStop always used against a DIV . Consider the following:
I have always used the Scriptmanager to handle all AJAX calls, but I am
I always used a normal PHP file and just defined the variables in that
I've always used ajax to load() the contents of a DOM element but now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.