Hi, in my iOS game, I'm storing the fixture definition as a property of a game object class , which means each game object has a physical representation. Then when the game starts, I retrieve the fixture definition from the game objects and create physical bodies accordingly. My code is like this:
@interface GameObject : NSObject
@property b2FixtureDef fixtureDef
@property CGSize size
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.1f;
fixtureDef.shape = &shape;
Then in GameLogic, I loop through all the fixtures of the game objects and create the associating physical bodies.
But it gives me exc_bad_access when I do body->createFixture(fixtureDef), in particular, the error is at line
m_shape = def->shape->Clone(allocator);
in b2Fixture::Create. I think the problem is my shape object is not retained when I retrieve the fixture definition in GameLogic. I am doing something wrong. I'm not familiar with C++, so I hope somebody can point me to how I can achieve the above-described task.