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 7980737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:10:07+00:00 2026-06-04T10:10:07+00:00

Hi I run into EXC_BAD_ACCESS in my code, I’m trying to run a method

  • 0

Hi I run into EXC_BAD_ACCESS in my code,

I’m trying to run a method in class PurchaseTowerMenuLayer,
method is from class UnitDatabase:

PurchaseTowerMenuLayer.m:

delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// getUnitDatabase returns UnitDatabase class from GameScene class

[[[delegate getGameScene] getUnitDatabase] createUnit:@"t01"]; //EXC_BAD_ACCESS happens here

UnitDatabase.m:

-(void)createUnit:(NSString *)unitID
{

typeString = [unitID substringWithRange:NSMakeRange(0,1)];
numberString = [unitID substringWithRange:NSMakeRange(1,2)];

Unit *unit;

if(unitID == @"t00")
    [unit setUnitID:unitID];

etc...
}

What am I doing to get this error? How should it look like?

Thanks in advance!

  • 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-04T10:10:10+00:00Added an answer on June 4, 2026 at 10:10 am

    Alright, first separate the call [[[delegate getGameScene] getUnitDatabase] createUnit:@"t01"]; for three lines such as

    GameScene* scene = [delegate getGameScene];
    UnitDatabase* unitDatabase = [scene getUnitDatabase];
    [unitDatabase createUnit:@"t01"];
    

    This’ll allow you to pinpoint which call emits the EXC_BAD_ACCESS and you can collapse them back after if you prefer.

    After you identified which line emits the error, it’s usually a matter of finding where you haven’t called [[MyClass alloc] init];. For example, if getGameScene or getUnitDatabase return objects that weren’t alloc‘d/init‘d (or delegate too for that matter), then you want to make sure to do that at least before you return them.

    I can’t help much more without seeing more code but these errors often go like this. Make sure you alloc and initialize the objects you keep as members of other objects.

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

Sidebar

Related Questions

I've run into a EXC_BAD_ACCESS with a piece of code that deals with data
I've run into a little theoretical problem. In a piece of code I'm maintaining
I've run into some problems when trying to serialize my object to XML. The
I have run into a problem trying to modify a form I myself have
I run into some problems when trying to solve a problem I had with
Recently run into following problem using python 2.7: I have class like this: class
I run into following code in my project: html: <input type=button id=addmore value=Add more
I run into the following problem.I load my shaders from files.The shader program ,when
I've run into a problem while trying to create a generic ArrayAdapter. It probably
I try to invoke some block, but I run into a EXC_BAD_ACCESS. -(void) methodA

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.