iphone - EXC_BAD_ACCESS on NSMutableArray insertion -


i using nsmutablearray defined in cclayer subclass follows:

// //  gameoverscene.h //  cocos2dsimplegame // //  created ray wenderlich on 2/10/10. //  copyright 2010 ray wenderlich. rights reserved. //  #import "cocos2d.h"  @interface scolayer : cccolorlayer {     cclabelttf *_label;     cclabelttf *_howtoplay;     nsmutablearray *highscores;  }  @property (nonatomic, retain) cclabelttf *label; @property (nonatomic, retain) nsmutablearray *highscores; @property (nonatomic, retain) cclabelttf *back; + (id)initwithscore:(int)lastscore; +(void)print_label:(int)lb; +(void)menu; @end  @interface sco : ccscene {     scolayer *_layer; }  @property (nonatomic, retain) scolayer *layer;  @end 

here .m file class:

@implementation sco @synthesize layer = _layer;  - (id)init {      if ((self = [super init])) {         self.layer = [scolayer node];         [self addchild:_layer];     }     return self; }  - (void)dealloc {     [_layer release];     _layer = nil;     [super dealloc]; }  @end  @implementation scolayer @synthesize label = _label; @synthesize highscores ;  //@synthesize how_to_play ; @synthesize back; -(id) init {     if( (self=[super initwithcolor:ccc4(255,255,255,255)] )) {          cgsize winsize = [[ccdirector shareddirector] winsize];         self.label = [cclabelttf labelwithstring:@"" fontname:@"arial" fontsize:16];         //self.how_to_play  = [cclabelttf labelwithstring:@"" fontname:@"arial" fontsize:32];          self.highscores =  [[nsmutablearray alloc] initwithobjects:nil ];      //  [highscores addobject:@"asdf"];      //  nslog(@"hig %@", [highscores objectatindex:0]);         _label.color = ccc3(0,0,0);         _label.position = ccp(winsize.width/2, winsize.height/2);          [self addchild:_label z:100];          [self runaction:[ccsequence actions:                          [ccdelaytime actionwithduration:3],                          [cccallfunc actionwithtarget:self selector:@selector(gameoverdone)],                          nil]];         ccsprite *bk1 =[ccsprite spritewithfile:@"bg3.png" ];//rect: cgrectmake(0, 0, 40, 480)];          [bk1 setposition:ccp(160, 239)];         [self addchild:bk1 z:0];          ccmenuitem *back = [ccmenuitemimage                              itemfromnormalimage:@"gamebackbutton.png" selectedimage:@"gamebackbutton.png"                              target:self selector:@selector(back_game:)];          ccmenu *menu1 = [ccmenu menuwithitems:back,nil];          menu1.position = ccp(70, 100);         [menu1 alignitemsverticallywithpadding: 40.0f];         //  [self addchild:menu z: 2];         [self addchild:menu1 z: 0];       }        return self; } 

in function:

+(id)initwithscore:(int)lastscore {     nslog(@"score %d", lastscore);      //nsmutablearray *highscores =  [[nsmutablearray alloc] initwithobjects:nil ];     //[highscores addobject:@"asdf"];     if([highscores count] == 0) } 

i want use highscores array , insert data (lastscore), when application exits exc_bad_access signal. how can fix error?

the + before method declaration indicates, class method. have no access instance variables.

i think more want:

-(id)initwithscore:(int)lastscore {     nslog(@"score %d", lastscore);      if(!self = [super init])        return nil;      highscores =  [[nsmutablearray alloc] init];     [highscores addobject:lastscore];     return self; } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -