EXC_BAD_ACCESS when returning a CGRect in iPhone
- by pabloruiz55
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...