So I've got a b2world set up and I want to update the objects of it.
The *sprite assignment is crashing my program with a bad access error. I know for sure UserData has been assigned. Breakpoints show the UserData has info in it and it is passing the NULL check.
All object sprites are a subclass of CCSprite.
alternate version:
Here it is crashing on the 'ud' assignment
more code: http://pastebin.com/sZxhPPtf
What could I be doing wrong?
Edit: Fixed!
Had to assign userdata like so:
Code:
for (b2Body *b = _world->GetBodyList(); b; b = b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *sprite = (__bridge CCSprite *)b->GetUserData();
// update *sprite
}
}
if (b->GetUserData() != NULL) {
CCSprite *sprite = (__bridge CCSprite *)b->GetUserData();
// update *sprite
}
}
The *sprite assignment is crashing my program with a bad access error. I know for sure UserData has been assigned. Breakpoints show the UserData has info in it and it is passing the NULL check.
All object sprites are a subclass of CCSprite.
alternate version:
Code:
for (b2Body *b = _world->GetBodyList(); b; b = b->GetNext()) {
if (b->GetUserData() != NULL) {
id ud = (__bridge id)b->GetUserData();
b2Vec2 b2position;
float32 b2angle;
if ([ud isKindOfClass:[Plane class]]) {
Plane *sprite = (__bridge Plane *)b->GetUserData();
b2position = b2Vec2(sprite.position.x / PTM_RATIO, sprite.position.y / PTM_RATIO);
b2angle = -1 * CC_DEGREES_TO_RADIANS(sprite.rotation);
}
b->SetTransform(b2position, b2angle);
}
}
if (b->GetUserData() != NULL) {
id ud = (__bridge id)b->GetUserData();
b2Vec2 b2position;
float32 b2angle;
if ([ud isKindOfClass:[Plane class]]) {
Plane *sprite = (__bridge Plane *)b->GetUserData();
b2position = b2Vec2(sprite.position.x / PTM_RATIO, sprite.position.y / PTM_RATIO);
b2angle = -1 * CC_DEGREES_TO_RADIANS(sprite.rotation);
}
b->SetTransform(b2position, b2angle);
}
}
Here it is crashing on the 'ud' assignment
more code: http://pastebin.com/sZxhPPtf
What could I be doing wrong?
Edit: Fixed!
Had to assign userdata like so:
Code:
spriteBodyDef.userData = (__bridge_retained void *)_plane;