I have two functions that are virtually the same with a few small differences in code, one to create a static body and one to create a dynamic body, however if I call both of them it results in a segmentation fault, but I'm not quite sure why as far as I know I'm not trying to redefine any objects (other than bbox which is a box2d * body).
I've tried debugging it it appears the issue is caused by b2FixtureDef but I again Don't know exactly what it is, From looking at the memory somewhere there is an allocation issue as 0xfeeefeee shows up in a dump of the registers.
as long as I only use one its fine but when I use two or more it crashes. if someone could point me in the right direction ( the code is valid 0 errors and 0 warnings so I'm not looking for handouts )
void entity::setAsPlatform(float hx, float hy, b2World world)
{
b2BodyDef platformDef;
platformDef.position.Set(bbox_pos.x,bbox_pos.y);
b2Body * platform = world.CreateBody(&platformDef);
b2PolygonShape platformShape;
platformShape.SetAsBox(hx, hy);
b2FixtureDef platformFixture;
platformFixture.shape = &platformShape;
platform->CreateFixture(&platformFixture);
bbox = platform;
}
void entity::setAsPlayer(float hx, float hy, b2World world)
{
b2BodyDef platformDef;
platformDef.position.Set(bbox_pos.x,bbox_pos.y);
platformDef.type = b2_dynamicBody;
b2Body * platform = world.CreateBody(&platformDef);
b2PolygonShape platformShape;
platformShape.SetAsBox(hx, hy);
b2FixtureDef platformFixture;
platformFixture.shape = &platformShape;
platform->CreateFixture(&platformFixture);
bbox = platform;
}
and in main.cpp
entity platform("Platform", 20, 500);
platform.setAsPlatform(2.0f, 50.0f, world);
entity player("Player", 0, 20);
player.setAsPlayer(1.0f,1.0f,world);