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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:28:19+00:00 2026-05-24T09:28:19+00:00

I am working on a game and in my init method it gives EXC_BAD_ACCESS

  • 0

I am working on a game and in my init method it gives EXC_BAD_ACCESS when I do [self loadGravityCenters]. Here is the definition of that method:

-(void) loadGravityCenters {

    //These P1, P2, etc. are for seeing where the EXC_BAD_ACCESS is in the method.
    printf("P1\n");
    //Get and open the file with coordinates
    NSString *filePath =  [[NSBundle mainBundle] pathForResource: @"gravitycenter" ofType: @"ballpoint"];
    FILE *fileHandle = fopen([filePath cStringUsingEncoding:NSASCIIStringEncoding],"r");
    //First array for storing the coordinates from the file.
    NSMutableArray *coord;
    //Vanilla C doesn't have an NSMutableArray, use tempCoord to place it in the NSMutableArray.
    int tempCoord;
    //i is used to keep track of where to assign stuff in coord).
    int i = 0;
    while (!feof(fileHandle)) { //Read file.
        //Next check point.
        printf("P2\n");
        //Assign tempCoord a number from file.
        fscanf(fileHandle, "%d", &tempCoord);
        //Convert the integer to NSNumber (so I can put it in coord.
        NSNumber *intToNSNumber = [NSNumber numberWithInt:tempCoord];
        [coord insertObject:intToNSNumber atIndex:i];
        i++;
    }
    for (int j = 0; j < [coord count]; j+=2) { //Make the coord array into an array of CGPoints
        printf("P3\n"); //Check point.
        //Assign a gravityCenters (declared in header) a series of points.
        [gravityCenters addObject:[NSValue valueWithCGPoint:CGPointMake([[coord objectAtIndex:j] floatValue], [[coord objectAtIndex:j+1] floatValue])]];
    }

    for (int j = 0; j < [gravityCenters count]; j++) {
        printf("P4\n"); //Last checkpoint.
        //gravityWells (declared in header) is used to store CCSprites, make a bunch of sprites with the positions stored in gravityCenters.
        [gravityWells addObject:[CCSprite spriteWithFile:@"GravityCenter.png"]];
        [[gravityWells objectAtIndex:j] setPosition:[[gravityCenters objectAtIndex:j] CGPointValue]];
        printf("gravityWell=%f,%f\n", ((CCSprite *)[gravityWells objectAtIndex:j]).position.x, ((CCSprite *)[gravityWells objectAtIndex:j]).position.y);
        [self addChild:[gravityWells objectAtIndex:j]];
    }
}

To summarize:

Make an array of intgers that stores coordinates. Convert it so it can be placed in an array of CGPoints. Make a bunch of CCSprites and give them the coordinates from the array filled with CGPoints.

The file I am using looks like this:

70 100
80 89
46 545

The program fails at checkpoint P3. I’ve tried replacing the line:

    for (int j = 0; j < [gravityCenters count]; j++) {

With:

    for (int j = 0; j < [coord count]-2; j+=2) {
    //And:
    for (int j = 0; j < [coord count]-3; j+=2) {

Wondering it is only an out-of-bounds thing. But doing what I did above doesn’t seem to change anything. Any help would be greatly appreciated.

  • 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-24T09:28:20+00:00Added an answer on May 24, 2026 at 9:28 am

    You need to allocate the array first before you can use it. Try:

    NSMutableArray *coord = [[NSMutableArray alloc] init];
    

    Hope that helps!

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

Sidebar

Related Questions

Im currently working on a game that uses multi touch to apply zoom to
I'm working on a game that uses local area network. Like most of multiplayer
I am working on a game that will have a two dimensional board of
I'm working on an iPhone game that has a bunch of monsters. Each monster
I'm currently writing a class for a game I'm working on that controls application
Working on game where plates will be falling from top to bottom. Some plates
I am working on game application and i use AnimationDrawable for image change. but
I've been trying to get this Sudoku game working, and I am still failing
Im working on a game, and ive seen a lot of memory consuption, im
I'm working on board game based on playing cards, and following is the prototype

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.