cocos2d 8.2 + box2d: storing b2Body in an array

Hi there,

I am trying to simplify the code inside my iPhone app. I'm using cocos2d latest release, and box2d (latest I believe)...

I would like to store initiate a set of 'b2Body' bodies in an array to simply my code, except have not had luck with it.
I declared it within a layer class as a variable:

b2body *component[3];

Then created a method as follows:

-(void) addComponent:(int)targetBody x:(float)px y:(float)py width:(float)w height:(float)h;
{
//Create the body
b2BodyDef bodytDef;
bodyDef.position.Set(px/12, py/12);
bodyDef.linearDamping = 1;
bodyDef.angularDamping = 3;

//Create body in world
component[targetBody] = world->CreateBody(&bodyDef);

//Create the shape for body
b2PolygonShape alignedBoxDef;
b2FixtureDef shapefixtureDef;
alignedBoxDef.SetAsBox(w,h);
shapefixtureDef.shape = &alignedBoxDef;
shapefixtureDef.density = 1.0f;
shapefixtureDef.friction = 0.35f;
component[targetBody]->CreateFixture(&shapefixtureDef);

//Is body a sensor?
//targetBody.isSensor = s;
}

When I build, the app installs and loads correctly, however when I run this particular layer, the app halts, and gives me the following error during the debug session:

EXC_BAD_ACCESS, and points to a function for b2Vec inside the box2d code....

I am almost certain it is the way I have declared it... Can anyone help?

(I am sure its something fundamentally simple, and I just have been staring at the code too long! 🙂)
Is targetBody ever greater than 2?

Original thread: https://box2d.org/forum/viewtopic.php?t=3903