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

  • Home
  • SEARCH
  • 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 7551593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:32:13+00:00 2026-05-30T10:32:13+00:00

Been trying to solve this error for ages now, hoping that someone here can

  • 0

Been trying to solve this error for ages now, hoping that someone here can help! 🙂

I am using Cocos2d with Objective-C and have a simple game. I have just added a ‘restart game’ button that takes you back to the main menu so that you can choose to start a new game. The problem is i am getting EXC_BAD_ACCESS upon re-starting the game.

   [self performSelector:@selector(drawone) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawtwo) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawthree) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawfour) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawfive) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawsix) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawseven) withObject:nil afterDelay:3];
     [self performSelector:@selector(draweight) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawnine) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawten) withObject:nil afterDelay:3];

I am running the above code in ‘init’ and this causes the game to crash on the second play through on line

-(void)drawone {

However, if i am to comment out some of the above code e.g

  [self performSelector:@selector(drawone) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawtwo) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawthree) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawfour) withObject:nil afterDelay:3];
    [self performSelector:@selector(drawfive) withObject:nil afterDelay:3];

     /* [self performSelector:@selector(drawsix) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawseven) withObject:nil afterDelay:3];
     [self performSelector:@selector(draweight) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawnine) withObject:nil afterDelay:3]; */

     [self performSelector:@selector(drawten) withObject:nil afterDelay:3];

Then i get EXC_BAD_ACCESS on -(void)drawfive this time (still on second play)

Finially, commenting out more of the code e.g

    [self performSelector:@selector(drawone) withObject:nil afterDelay:3];

    /*  [self performSelector:@selector(drawtwo) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawthree) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawfour) withObject:nil afterDelay:3];
    [self performSelector:@selector(drawfive) withObject:nil afterDelay:3];
    [self performSelector:@selector(drawsix) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawseven) withObject:nil afterDelay:3];
     [self performSelector:@selector(draweight) withObject:nil afterDelay:3];
     [self performSelector:@selector(drawnine) withObject:nil afterDelay:3]; */

     [self performSelector:@selector(drawten) withObject:nil afterDelay:3];

And it makes it to the 6th play through (you can restart it 5 times) before getting EXC_BAD_ACCESS on -(void)drawone

The fact that the EXC_BAD_ACCESS changes places and when it appears leads me to assume that there is not a problem in -(void)drawone since, in some cases, it will run that without problem. I heard that using zombies to debug it could help: after trying unfortunately it did not. I am new to Objective-C so i apologise if this is a simple error. Thank you in advance.

Here is drawone:

-(void)drawone
 {

onepos = (arc4random() % 10) + 1;


if(positions[(onepos - 1)] != 0)
{
    positions[(onepos - 1)] = 0;
    if(onepos == 1)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp(53,420);
        [self addChild:onem];

    }
    else if(onepos == 2)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 1)),420);
        [self addChild:onem];


    }
    else if(onepos == 3)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 2)),420);
        [self addChild:onem];


    }
    else if(onepos == 4)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp(53,300);
        [self addChild:onem];


    }
    else if(onepos == 5)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 1)),300);
        [self addChild:onem];


    }
    else if(onepos == 6)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 2)),300);
        [self addChild:onem];


    }
    else if(onepos == 7)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp(53,180);
        [self addChild:onem];


    }
    else if(onepos == 8)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 1)),180);
        [self addChild:onem];


    }
    else if(onepos == 9)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 2)),180);
        [self addChild:onem];


    }
    else if(onepos == 10)
    {
        CCMenuItemImage *one = [CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"onepressed.png"

                                                             target:self
                                                           selector:@selector(oneclick:)];

        onem = [CCMenu menuWithItems:one, nil];
        onem.positionInPixels = ccp((53 + (106 * 1)),60);
        [self addChild:onem];


    }

}
else
{

    [self drawone];

}

}

and i have global variables:

int positions[] = {1,2,3,4,5,6,7,8,9,10};
int currentclick = 10; 
int onepos;
NSTimeInterval starttime;
CCMenu* onem;
CCMenu* twom;
CCMenu* threem;
CCMenu* fourm;
CCMenu* fivem;
CCMenu* sixm;
CCMenu* sevenm;
CCMenu* eightm;
CCMenu* ninem;
CCMenu* tenm;

Again, i am new to objective-c, so am probably doing something really stupid

  • 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-05-30T10:32:14+00:00Added an answer on May 30, 2026 at 10:32 am

    The fact that the EXC_BAD_ACCESS changes places and when it appears
    leads me to assume that there is not a problem in -(void)drawone
    since, in some cases, it will run that without problem.

    That may or may not be true. The fact that your code doesn’t always crash doesn’t mean that there’s not a problem. EXC_BAD_ACCESS means that your code is accessing a bad pointer somewhere. It sounds like you’ve got an uninitialized pointer in your code, and your code is crashing whenever that pointer happens to point to an invalid address. If the pointer happens to point to some valid object or contains nil (either of which can easily happen as the result of values left on the stack by other methods) then your code won’t crash.

    The way to debug this is to get the code to crash, and then use the debugger to look at the code at the point where the crash happened. Take a look at the variables that are used on the line that caused the exception. If the crash happened in some method that’s not yours (somewhere in a framework) back up the stack looking for the first place where you can see your code and check that instead.

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

Sidebar

Related Questions

I've been trying to solve this problem for a while now and I can't
I've been trying to solve this problem for over an hour now, and can't
I've been trying to solve this problem for a number of days now but
I've been trying to solve this problem for hours now and i cannot figure
I've been trying to solve this for a few hours now. I am compiling
I've been trying to solve this for hours now but came up with nothing.
I have been trying to solve this bug for awhile now. It's a CXF,
I've been trying to solve this problem for a while now, and I'm at
So I've been trying to solve this problem for a matter of hours now.
I have been trying to solve this issue for a day now and have

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.