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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:50:04+00:00 2026-06-01T12:50:04+00:00

I don’t understand why I’m getting a EXC BAD ACCESS error when I call

  • 0

I don’t understand why I’m getting a EXC BAD ACCESS error when I call the mineHit method in my .m file. I understand that it’s indicating that the button array has been released, but I don’t understand why It would have been released at all.

#import "basicsViewController.h"

@implementation basicsViewController
@synthesize resetGame;
@synthesize scoreLabel;
@synthesize timeLabel;
@synthesize time;
@synthesize score;

-(void)newGame{
int index=0;
int yAxis=70;
for(int y=0;y<100;y=y+10){
    int xAxis=20;
    for( int x = 1; x < 11; x++) {
        buttonArray[index] = [[UIButton alloc]init];
        buttonArray[index] = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [buttonArray[index] setTag:index];
        [buttonArray[index] addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        buttonArray[index].frame = CGRectMake(xAxis, yAxis, 26.0, 26.0);
        NSLog(@"tag:%d xAxis:%d yAxis:%d",buttonArray[index].tag,(int)buttonArray[index].frame.origin.x,(int)buttonArray[index].frame.origin.y);
        [self.view addSubview:buttonArray[index]];
        xAxis=xAxis+28;
        index=x+y;
    }
    yAxis=yAxis+28;
}

//generate bombs

for (int bombs=0;bombs<10;bombs++){

    bombArray[bombs]= (arc4random()%99);
    //TODO compare against bombArray to make sure of no duplicates
    NSLog(@"BOMB AT %d",bombArray[bombs]);

}

}



- (IBAction)resetPress:(id)sender {
[self newGame];
}


- (void)buttonClicked:(UIButton*)button
{
BOOL hit;
NSLog(@"SELECTED BUTTON:%d",button.tag);
for (int b=0;b<10;b++){
    if (button.tag==bombArray[b]){
        //BOMB HIT
        hit=YES;
        b=10;
    }
    else {
        //no bomb
        hit=NO;
    }
}
if (hit==YES){
    //if hit
    NSLog(@"HIT AT %d",button.tag);
    [self mineHit];

}
else {
    //if not hit
    NSLog(@"%d is clean",button.tag);
    [self cleanHit:button];

}
}

-(void)mineHit{

for (int d=0;d<100;d++){
    NSLog(@"%i",buttonArray[d].tag);
    buttonArray[d].enabled=NO;
    [buttonArray[d] setTitle:@"*" forState:UIControlStateDisabled];
}

}
-(void)cleanHit:(UIButton*)button{
button.enabled=NO;
[button setTitle:@"!" forState:UIControlStateDisabled];

}

- (void)viewDidLoad
{
[super viewDidLoad];
[self newGame];

}

- (void)viewDidUnload
{
[self setResetGame:nil];
[self setScoreLabel:nil];
[self setTimeLabel:nil];
[super viewDidUnload];

}
@end

Here is my .h file

#import <UIKit/UIKit.h>
NSInteger bombArray[];
UIButton *buttonArray[];
@interface basicsViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *resetGame;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property int time;
@property int score;
-(void)newGame;
-(void)buttonClicked:(UIButton*)button;
-(void)mineHit;
-(void)cleanHit:(UIButton*)button;

@end
  • 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-01T12:50:06+00:00Added an answer on June 1, 2026 at 12:50 pm

    When I compile your code I get four warnings. All four warnings are the same and say:

    Tentative array definition assumed to have one element

    The warnings apply to the definition of your bombArray and buttonArray arrays in the interface (.h) file.

    If we give the two arrays a size your -mineHit method works fine.

    Change the beginning of your .h file to:

    #import <UIKit/UIKit.h>
    NSInteger bombArray[10];
    UIButton *buttonArray[100];
    @interface basicsViewController : UIViewController
    

    The compiler generates warnings for a reason and it is a good idea to try and get your code to compile cleanly with no warnings or errors.

    Update: While we are here there is no reason why you couldn’t move these arrays inside the interface and declare them as instance variables. Doing this would mean that the arrays are associated with an individual instance of the view controller. It is unlikely that you’d have multiple instances of this view controller but it is better to do it correctly now than get bitten later.

    #import <UIKit/UIKit.h>
    
    @interface basicsViewController : UIViewController {
        NSInteger bombArray[10];
        UIButton *buttonArray[100];
    }
    

    Interestingly, moving the declaration into the interface turns the warnings into errors.

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

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
Don't quite understand why this copy constructor is not invoked when I build with
Don't know what's wrong here, when I run the application it says Specified method
Don't ask why, but is there any way to suppress a failed linking error?
Don't know what to do with this error. How to add data in SQL
Don't worry, I'm not going to ask that question, yet again... I am wanting
DON'T ASK WHY but... I have a regex that needs to be case insensitive
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't ask me why but i can't use this method because I need to

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.