Sabha B
Sabha B

Reputation: 2089

Application crash - debug says "objc_msgsend"

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

@end`

Table

`@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 size; -(id) initWithTableSize:(CGSize)argSize; -(void)render; -(Tile *) objectAtX: (int) x Y: (int) y; `

Calling Class (Main)

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

Implementation

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

} return self; }

. . .

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

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".

Upvotes: 2

Views: 5261

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

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.

Upvotes: 7

Related Questions