user2577959
user2577959

Reputation: 295

Objective C - ERROR: Thread 1: EXC_BAD_ACCESS code=2

I'm getting an error when trying to call a method.

The method

- (void)setSpeed:(GLKVector2)newSpeed{  //Error message (see title) points to here
    self.speed = GLKVector2Make(newSpeed.x, newSpeed.y);
}

The call

[self setSpeed:GLKVector2Make(0, 0)];

Any thoughts?

Upvotes: 3

Views: 2142

Answers (2)

Chuck
Chuck

Reputation: 237060

self.speed= sets the speed property using whatever accessor is chosen for it. the default name for the setter of a property named "speed" will be setSpeed:. This is the method you're using, it just keeps calling itself over and over and never stopping. You want to set the instance variable directly (if you just have an @property declaration and don't have an explicit @synthesize, this will be _speed).

Upvotes: 4

stosha
stosha

Reputation: 2148

try write

_speed = GLKVector2Make(newSpeed.x, newSpeed.y);

or

speed = GLKVector2Make(newSpeed.x, newSpeed.y);

instead of

self.speed = GLKVector2Make(newSpeed.x, newSpeed.y);

Upvotes: 10

Related Questions