Man, I don't even know where to start with this one. Okay, so I know this code is pretty sloppy in places, I'm just testing concepts out right now. I'm working with both Box2D and a library called SFML. What I'm about to lay out here I've done just fine in the past when I write it just into the main.cpp file.
I have these classes that define game objects (yes I know the naming terrible)
Code:
class SolidObject : public GameObject{
private:
protected:
public:
sf::Sprite Sprite;
b2Body* Body;
b2PolygonShape Shape;
b2FixtureDef fixtureDef;
sf::Sprite Sprite;
SolidObject();
~SolidObject();
};
class ImmobileObject : public SolidObject{
private:
sf::Image ImmobileImage;
protected:
public:
ImmobileObject();
~ImmobileObject();
ImmobileObject(b2World* World, int xpos, int ypos, int xsize, int ysize);
};
The constructor for ImmobileObject looks like this:
Code:
ImmobileObject::ImmobileObject(b2World* World, int xpos, int ypos, int xsize, int ysize){
b2BodyDef BodyDef;
BodyDef.type = b2_dynamicBody;
BodyDef.position.Set(xpos/10, -ypos/10);
Body = World->CreateBody(&BodyDef);
Shape.SetAsBox(xsize/20, ysize/20);
fixtureDef.shape = &Shape;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
Body->CreateFixture(&fixtureDef);
//Body->CreateFixture(&Shape, 0.0f);
b2Vec2 Position = Body->GetPosition();
ImmobileImage.Create(xsize, ysize, sf::Color(255, 255, 255));
Sprite.SetImage(ImmobileImage);
Sprite.SetCenter(xsize/2, ysize/2);
Sprite.SetPosition(10*Position.x, -10*Position.y);
}
And in main.cpp I call the constructor using this (I store all of my objects in a vector like this for the purposes of drawing everything with SFML)
Code:
Immobile.push_back(std::shared_ptr<ImmobileObject>(new ImmobileObject(&World, 50, 50, 10, 10)));
Now, this compiles and runs absolutely fine if, in construction, I use Body->CreateFixture(&Shape, 0.0f); instead of Body->CreateFixture(&fixtureDef);
EDIT: After investigation the problem is the fixtureDef.density = 1.0f setting. If I remove that, it compiles and runs fine.
If I do use the latter (because I'm trying to make a dynamic object, yes I know its called "immobile", I'm testing things) I get this:

And if I click "retry" it tells me that I've triggered a breakpoint and takes me to:

And so I have absolutely
no idea what I'm doing wrong. Any ideas?