应用程序崩溃 - 调试显示“objc_msgsend"; [英] Application crash - debug says "objc_msgsend"
问题描述
我已经为 iphone 启动了一个基于 2d tile 的游戏,我将直接跳转到我所拥有的课程和问题.我现在总共有 2 个类 Tile、Table 和 Base 主类瓦
I have started a 2d tile based game for iphone , i will jump directly to the class's i have and the issue. i have totally 2 class for now Tile , Table , and Base main class Tile
`@interface Tile : NSObject {
CCSprite *sprite;
CCSprite *outline;
int row,column;
BOOL highLight;
}
@property (nonatomic , retain)CCSprite *sprite;@property (nonatomic , retain)CCSprite *outline;
@property (nonatomic , retain)CCSprite *sprite; @property (nonatomic , retain)CCSprite *outline;
@property (nonatomic, readonly) int row, column;@property (nonatomic , readwrite)BOOL highLight;-(id) initWithSpriteName: (NSString*)argSpriteName Row:(int)argRow Column:(int)argColumn Position:(CGPoint)argPosition;
@property (nonatomic, readonly) int row, column; @property (nonatomic , readwrite)BOOL highLight; -(id) initWithSpriteName: (NSString*)argSpriteName Row:(int)argRow Column:(int)argColumn Position:(CGPoint)argPosition;
@end`
表
`@interface Table : NSObject {
CCLayer *layer;
CGSize size;
NSArray *icons;
NSMutableArray *content;
}@property(nonatomic, retain) NSMutableArray *content;@property(nonatomic, retain) CCLayer *layer;@property(nonatomic, readonly) CGSize 大小;-(id) initWithTableSize:(CGSize)argSize;-(无效)渲染;-(Tile *) objectAtX: (int) x Y: (int) y;`
} @property(nonatomic, retain) NSMutableArray *content; @property(nonatomic, retain) CCLayer *layer; @property(nonatomic, readonly) CGSize size; -(id) initWithTableSize:(CGSize)argSize; -(void)render; -(Tile *) objectAtX: (int) x Y: (int) y; `
调用类(主)
@interface HelloWorld : CCLayer
{
CGSize size;
Table *tableLayer;
}
@property (retain) Table *tableLayer;
实施
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
......
tableLayer = [[Table alloc] initWithTableSize:CGSizeMake(4,7) ];
tableLayer.layer = self;
[tableLayer render];
self.isTouchEnabled = YES;
self.isAccelerometerEnabled = YES;
[self schedule:@selector(render:)];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 30)];
}回归自我;}
...
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch = [touches anyObject];CGPoint location = [touch locationInView: [touch view]];CGPoint touchCorrected;touchCorrected.x = location.x;touchCorrected.y = 480 - location.y;int x = (int)(touchCorrected.x/48);int y = (int)(touchCorrected.y/48);printf("X = %d Y = %d \n",x,y);如果 (x!=0 && y!=0) {Tile *tile = [tableLayer objectAtX:(1) Y:(1)];[tile setHighLight:YES];}}
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView: [touch view]]; CGPoint touchCorrected; touchCorrected.x = location.x; touchCorrected.y = 480 - location.y; int x = (int)(touchCorrected.x/48); int y = (int)(touchCorrected.y/48); printf("X = %d Y = %d \n",x,y); if (x!=0 && y!=0) { Tile *tile = [tableLayer objectAtX:(1) Y:(1)]; [tile setHighLight:YES]; } }
在触摸结束回调中调用以下语句时我的程序崩溃
My program gets crashed when calling the following statement inside the touch end call back
Tile *tile = [tableLayer objectAtX:(1) Y:(1)];
我读过的博客很少,但真的很难理解消息传递背后的概念,请您解释一下应用程序崩溃结束objc_msgsend"的原因.
I have read few blogs but really having tough time to understand the concept behind messaging , could you please explain me what is cause for the application crash ends "objc_msgsend".
推荐答案
这很可能是内存管理错误.我会查看 Hamster Emporium 的博客文章,名为So you crashed in objc_msgSend()".很有帮助.
This is most likely a memory management error. I would check out Hamster Emporium's blog post called "So you crashed in objc_msgSend()". It's very helpful.
这篇关于应用程序崩溃 - 调试显示“objc_msgsend";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!