gpt4 book ai didi

objective-c - 应用程序崩溃 - 调试显示 "objc_msgsend"

转载 作者:行者123 更新时间:2023-12-04 06:43:57 24 4
gpt4 key购买 nike

我已经为 iphone 启动了一个基于 2d 图 block 的游戏,我将直接跳转到我的类(class)和问题。我现在总共有 2 个类 Tile 、 Table 和 Base 主类瓦

`@interface Tile : NSObject {
CCSprite *sprite;
CCSprite *outline;
int row,column;
BOOL highLight;
}<p></p>

<p>@property (nonatomic , retain)CCSprite *sprite;
@property (nonatomic , retain)CCSprite *outline;</p>

<p>@property (nonatomic, readonly) int row, column;
@property (nonatomic , readwrite)BOOL highLight;
-(id) initWithSpriteName: (NSString*)argSpriteName Row:(int)argRow Column:(int)argColumn Position:(CGPoint)argPosition;</p>

<p>@end`</p>

表格

`@interface Table : NSObject {
CCLayer *layer;
CGSize size;
NSArray *icons;
NSMutableArray *content;<p></p>

<p>}
@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;
` </p>

调用类(主要)

<code>@interface HelloWorld : CCLayer
{
CGSize size;
Table *tableLayer;
}
@property (retain) Table *tableLayer;</code>

实现

-(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)];<p></p>

<p>}
return self;
}</p>

<p>.
.
.</p>

<p>-(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];
}
}</p>

<p></p>

在触摸结束回调中调用以下语句时,我的程序崩溃了

   Tile *tile = [tableLayer objectAtX:(1) Y:(1)];

我读过一些博客,但真的很难理解消息背后的概念,你能解释一下应用程序崩溃的原因是什么结束“objc_msgsend”吗。

最佳答案

这很可能是内存管理错误。我会查看 Hamster Emporium's blog post called "So you crashed in objc_msgSend()" .这非常有帮助。

关于objective-c - 应用程序崩溃 - 调试显示 "objc_msgsend",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4506205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com