objective c - iOS app crashes with EXC_BAD_ACCESS -


i'm including full project nothing ambiguous.

a.h

#import <foundation/foundation.h>  @interface : nsobject -(void) zero; @end 

a.m

#import "a.h"  @implementation  #define width 3 #define height 3  uint8_t** _board;  -(void) 0 { for(int = 0; < width; i++)     for(int j = 0; j < height; j++)         _board[i][j] = 0; }  -(void)dealloc { for(int = 0; < width; i++)     free(_board[i]); free(_board); }  -(id) init { self = [super init]; if(self) {     _board = malloc(sizeof(uint8_t*)*width);     for(int = 0; < width; i++)         _board[i] = malloc(sizeof(uint8_t)*height); } return self; }  @end 

viewcontroller.h

#import <uikit/uikit.h>  @interface viewcontroller : uiviewcontroller @end 

viewcontroller.m

#import "viewcontroller.h" #import "a.h"  @implementation viewcontroller  a* _gameboard;  - (void)viewdidload { [super viewdidload];  _gameboard = [[a alloc] init]; [[a alloc] init];  [_gameboard zero]; }  @end 

specifically, program crashes in function 0 when setting _board. point out if remove

[[a alloc] init]; 

from viewcontroller's implementation, program doesn't crash. help, in advance.

you have several problems in code. first of all, doesn't make sense create a instance , not assign variable.

the main problem though you're not using instance variables (or properties) neither on viewcontroller (_gameboard) nor on a (uint8_t** _board).

making them instance variables (or properties) should fix issue.

ps: may want use nsarray instead of c-style arrays also.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -