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…
I could not solve this, i tried everything. All the objects accessed are ok,if i try to get a property from them just outside that method i get correct data, if i change the method to return anything else it works fine.
I solved this by having a general method on the main class and every object calls it passing itself to it. This way it works fine.