Box2D Forums

It is currently Tue May 21, 2013 9:20 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Jan 22, 2012 1:20 pm 
Offline

Joined: Sun Jan 22, 2012 1:08 pm
Posts: 3
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:
Image
And if I click "retry" it tells me that I've triggered a breakpoint and takes me to:
Image

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


Top
 Profile  
 
PostPosted: Mon Jan 23, 2012 5:43 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
You should be able to look in the stack trace to see what part of your code caused it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group