我有一个SpriteObject类:
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
然后在HelloScene类中,我得到了一个val SpriteObject * gridSprites [3] [3];
HelloWorldScene.h
@interface HelloWorld : CCLayer
{
SpriteObject *gridSprites[3][3];
}
我尝试像这样初始化gridSprites:
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;
}
如果我构建&amp;&amp;运行它,一切都很好,但如果我设置断点 line“gridSprites [i] [j] .spriteType = -1;”,并尝试跨过它, 应用程序崩溃,我发出错误消息说:
Current language: auto; currently objective-c
Program received signal: ?EXC_BAD_ACCESS?.
我开车疯了,有人可以帮助我,谢谢 事先......
答案 0 :(得分:0)
如果您仍然可以访问双数组,则无法释放..
在dealloc发布它..
表示:
-(void)dealloc
{
for(int i = 0; i<3 ; i++)
{
for(int j = 0; j<3; j++)
{
[gridSprites[i][j]release];
}
}
[super dealloc];
}