开发者

Sprite array init weird problem

I got a SpriteObject class:

SpriteObject.h

#import "cocos2d.h"

@interface SpriteObject : CCNode {

    int spriteType;
}

-(id) init;

@property(readwrite, assign) int spriteType;

@end

SpriteObject.mm

#import "SpriteObject.h"

@implementation SpriteObject
@synthesize spriteType;

-(id) init
{
    if ((self = [super init]))
    {

    }

    return (self);
}
@end

Then in the HelloScene class, I got a val SpriteObject *gridSprites[3][3];

HelloWorldScene.h

@interface HelloWorld : CCLayer
{
    SpriteObject *gridSprites[3][3];
}

I tried to init the gridSprites like this:

HelloWorldScene.m

-(id) init
{
    if( (self=[super init] )) {

        for(int i =0; i< 3 ; i++)
        {
            for(int j =0; j< 3 ; j++)
            {
                SpriteObject * s = [[SpriteObject alloc] init];
                gridSprites[i][j] = s;
                [s release];

                gridSprites[i][j].spriteType = -1;
            }
        }
    }
    return self;
}

If I build&&run it, everything is fine, but if I set a breakpoint at the line "gridSprites[i][j].spriteType = -1;", and try to step over it, the app crashes and I gor an error message sayin开发者_StackOverflow社区g:

Current language:  auto; currently objective-c
Program received signal:  ?EXC_BAD_ACCESS?.

I'm driving nuts, can anybody helps me out here, thanks in advance...


U cant release if you still wan access to the double array..

release it at the dealloc..

means:

-(void)dealloc
{
for(int i = 0; i<3 ; i++)
{
   for(int j = 0; j<3; j++)
    {
      [gridSprites[i][j]release];
    }
}
[super dealloc];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜