EXC_BAD_ACCESS when returning a CGRect in iPhone

Posted by pabloruiz55 on Stack Overflow See other posts from Stack Overflow or by pabloruiz55
Published on 2010-05-27T11:52:50Z Indexed on 2010/05/27 12:01 UTC
Read the original article Hit count: 124

Filed under:

I have a class which must return a CGRect from one of its methods:

-(CGRect)myRect
{
    CGRect rect = CGRectMake(self.mySprite.position.x,self.mySprite.position.y,self.mySprite.textureRect.size.width, self.mySprite.textureRect.size.height);
    return rect;
}

I get an exc_bad_access as soon as i try to access the mySprite ivar.

Thing is if i call it, the instance variable mySprite is full of garbage. BUT if i change the function to return void, self.mySprite does contain the correct data.

-(void)myRect
{
    CGRect rect = CGRectMake(self.mySprite.position.x,self.mySprite.position.y,self.mySprite.textureRect.size.width, self.mySprite.textureRect.size.height);
    return rect;
}

that does not crash when accessing mySprite...

© Stack Overflow or respective owner

Related posts about iphone