I 'm writing a little game, but I've got problems when creating my shapes.
I store a pointer to the b2World in my class IWorld
The IEntity class stores the graphics and some definitions for the bodies, and a vector for b2ShapeDefs
The error happens when creating the shapes for the body in IWorld::AddEnt, something in a file named xutility triggers a breakpoint(strange, but the IDE say that).
The code part whics creates the body:
How should i solve this problem?
I store a pointer to the b2World in my class IWorld
Code:
class IWorld
{
public:
IWorld(f64 g, f32 lbound, f32 ubound);
~IWorld(void);
void Draw(IVideoDriver* video) const; //drawing
f64 g;
IEntity* AddEnt(const IEntity& ent); //adding entities to the world, Bodies are created here
bool RemoveEnt(u32 index);
bool RemoveEnt(IEntity* ent);
void Refresh(); //Updates position and angle values
b2World* physics;
private:
std::vector<IEntity> ents;
};
{
public:
IWorld(f64 g, f32 lbound, f32 ubound);
~IWorld(void);
void Draw(IVideoDriver* video) const; //drawing
f64 g;
IEntity* AddEnt(const IEntity& ent); //adding entities to the world, Bodies are created here
bool RemoveEnt(u32 index);
bool RemoveEnt(IEntity* ent);
void Refresh(); //Updates position and angle values
b2World* physics;
private:
std::vector<IEntity> ents;
};
The IEntity class stores the graphics and some definitions for the bodies, and a vector for b2ShapeDefs
Code:
class IEntity
{
public:
IEntity(ITexture* text, bool usePhysics=false);
IEntity(ITexture* text, std::vector<b2ShapeDef> shapes);
IEntity(ITexture* text, position2d<s32> pos, rect<s32> sourceRect, std::vector<b2ShapeDef> shapes);
IEntity(ITexture* text, position2d<s32> pos, rect<s32> sourceRect);
IEntity(ITexture* text, b2ShapeDef shape);
IEntity();
~IEntity(void);
void SetFlag(u32 flag, bool value);
//void Refresh(); // not needed
ITexture* graf;
rect<s32> srcRect;
position2d<s32> pos;
f32 angle; //intial angle, later it's updated from the body every frame
b2Body* physics;
std::vector<b2ShapeDef> shapes; //Storing the Shapedefs until creating the body
f32 mass; //ha nem használunk automass-t
std::vector<bool> flags;
private:
void SetFlagSize(); //saving some lines of code with this
};
{
public:
IEntity(ITexture* text, bool usePhysics=false);
IEntity(ITexture* text, std::vector<b2ShapeDef> shapes);
IEntity(ITexture* text, position2d<s32> pos, rect<s32> sourceRect, std::vector<b2ShapeDef> shapes);
IEntity(ITexture* text, position2d<s32> pos, rect<s32> sourceRect);
IEntity(ITexture* text, b2ShapeDef shape);
IEntity();
~IEntity(void);
void SetFlag(u32 flag, bool value);
//void Refresh(); // not needed
ITexture* graf;
rect<s32> srcRect;
position2d<s32> pos;
f32 angle; //intial angle, later it's updated from the body every frame
b2Body* physics;
std::vector<b2ShapeDef> shapes; //Storing the Shapedefs until creating the body
f32 mass; //ha nem használunk automass-t
std::vector<bool> flags;
private:
void SetFlagSize(); //saving some lines of code with this
};
The error happens when creating the shapes for the body in IWorld::AddEnt, something in a file named xutility triggers a breakpoint(strange, but the IDE say that).
The code part whics creates the body:
Code:
if (entp->flags[ENTFLAG_USEPHYSICS]) //if we want to use physics
{
b2BodyDef bodydef; //creating the bodydef
bodydef.position.Set(entp->pos.X/PIXEL_METER, entp->pos.Y/PIXEL_METER);//setting the position
bodydef.angle=entp->angle;
if (!entp->flags[ENTFLAG_AUTOSHAPE])//autoshaping using the border of the graphics image
{
if (!entp->flags[ENTFLAG_AUTOMASS]) // if not setting the mass from shapes
{
bodydef.massData.mass = entp->mass;
}
entp->physics= this->physics->CreateBody(&bodydef);
for(u32 i=0; i<(entp->shapes.size());i++)// looping through the shapes vector
{
entp->physics->CreateShape(&entp->shapes[i]); //ERROR happens here
}
if (entp->flags[ENTFLAG_AUTOMASS])
{
entp->physics->SetMassFromShapes();
}
}
else
{ //AUTOSHAPE code
bodydef.massData.mass = entp->mass;
dimension2d<s32> size= entp->graf->getSize();
b2PolygonDef shDef= b2PolygonDef(); //error here too
shDef.SetAsBox((size.Width/PIXEL_METER)/2,(size.Height/PIXEL_METER)/2);
entp->physics= this->physics.CreateBody(&bodydef);
entp->physics.CreateShape(&shDef);
}
}
{
b2BodyDef bodydef; //creating the bodydef
bodydef.position.Set(entp->pos.X/PIXEL_METER, entp->pos.Y/PIXEL_METER);//setting the position
bodydef.angle=entp->angle;
if (!entp->flags[ENTFLAG_AUTOSHAPE])//autoshaping using the border of the graphics image
{
if (!entp->flags[ENTFLAG_AUTOMASS]) // if not setting the mass from shapes
{
bodydef.massData.mass = entp->mass;
}
entp->physics= this->physics->CreateBody(&bodydef);
for(u32 i=0; i<(entp->shapes.size());i++)// looping through the shapes vector
{
entp->physics->CreateShape(&entp->shapes[i]); //ERROR happens here
}
if (entp->flags[ENTFLAG_AUTOMASS])
{
entp->physics->SetMassFromShapes();
}
}
else
{ //AUTOSHAPE code
bodydef.massData.mass = entp->mass;
dimension2d<s32> size= entp->graf->getSize();
b2PolygonDef shDef= b2PolygonDef(); //error here too
shDef.SetAsBox((size.Width/PIXEL_METER)/2,(size.Height/PIXEL_METER)/2);
entp->physics= this->physics.CreateBody(&bodydef);
entp->physics.CreateShape(&shDef);
}
}
How should i solve this problem?