Hello! I started using box2D yesterday. I wanted to create simple class to integrate my graphics engine with box2d.
I haven't even started to program when i got the problem:
The program is just crashing after start.
I don't know what i did wrong, the debugger shows me that the problem is in destructor.
In the console i can see:
Here's the test code:
Thanks for answers!
I haven't even started to program when i got the problem:
The program is just crashing after start.
I don't know what i did wrong, the debugger shows me that the problem is in destructor.
In the console i can see:
Quote:
Assertion failed: m_bodyCount > 0 file (...) B2World.cpp line 133
Here's the test code:
Code:
#include <Box2D/Box2D.h>
#include <vector>
class shape
{
public:
shape(b2World&);
~shape();
private:
b2Body* physical;
};
shape::~shape()
{
if(physical != nullptr) {
physical->GetWorld()->DestroyBody(physical);
physical = nullptr;
}
}
shape::shape(b2World& world)
: physical(nullptr)
{
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(1.0f, 1.0f);
physical = world.CreateBody(&bodyDef);
//skipping fixture etc..
}
int main()
{
b2Vec2 gravity(0.0f,10.0f);
b2World world(gravity, true);
std::vector<shape> objects;
objects.push_back(shape(world));
objects.clear();
while(true)
{
// world.Step(1/60.f, 8, 3);
}
}
#include <vector>
class shape
{
public:
shape(b2World&);
~shape();
private:
b2Body* physical;
};
shape::~shape()
{
if(physical != nullptr) {
physical->GetWorld()->DestroyBody(physical);
physical = nullptr;
}
}
shape::shape(b2World& world)
: physical(nullptr)
{
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(1.0f, 1.0f);
physical = world.CreateBody(&bodyDef);
//skipping fixture etc..
}
int main()
{
b2Vec2 gravity(0.0f,10.0f);
b2World world(gravity, true);
std::vector<shape> objects;
objects.push_back(shape(world));
objects.clear();
while(true)
{
// world.Step(1/60.f, 8, 3);
}
}
Thanks for answers!