Hey guys!
I initially did not want to bother you with a probably stupid question again, but this error is driving me mad.
I included Box2D in my project, and started by creating an empty world and wanting to add a DebugDraw.
If I add a "DebugDraw", I get error nr.1. And if I just try to "step" the world, I get error nr.2, regardless of wether it is an empty world or not. Both errors are access violations, so presumably there is something unitialized somewhere (I don't get why, though.)
I even tried to simplify the code down to a minimum in order to find the error, but even then it does not work. Here is my code:
I'm using this DebugDraw class: https://github.com/MrPlow442/Box2D-SFML2-Debug-Draw
Variables
b2World* gameWorld;
//World step settings
int velIters, posIters;
//DEBUG
SFMLDebugDraw debugDraw;
World-setup
IngameState::IngameState(Morphscape* ms, b2World* loadedLevel) : GameState(ms), gameWorld(loadedLevel), debugDraw(ms->getRenderer()->getRenderTarget()) {
//World is initially given as argument, but in order to simplify, I create a completely new instance here.
gameWorld = new b2World(b2Vec2(0, 0));
//Nothing important, just some numbers. I could actually have omitted that part.
velIters = 6;
posIters = 2;
gameWorld->SetDebugDraw(&debugDraw);
debugDraw.SetFlags(b2Draw::e_shapeBit);
}
Update
void IngameState::update(const float delta){
std::cout << delta/1000 << std::endl; //0.033 - Exactly right.
gameWorld->Step(delta/1000, velIters, posIters); //Error Nr.2
}
Render
void IngameState::render(const float interpolation){
gameWorld->DrawDebugData(); //Error Nr.1
}
As you can see I did not do anything complicated: I just created a world, set it up, and am trying to update and render it.
Now the actual errors:
- Access Violation on b2Draw's GetFlags() - Which basically is just a method that returns the argument given in SetFlags OR 0. I have NO CLUE why it should be null or something. When I remove everyline having something to do with the debugdraw, this error obviously goes away. (The error happens in the DrawDebugData() method though.)
- Access Violation on b2Contact's GetFixtureA(). No idea how this can happen since I don't have a single fixture in the world anyway. And if I add some, the error doesnt go away either. Full call traceback for this error:
> main()
> ... some of my methods
> IngameState::update(...)
> b2World::Step(...)
> b2ContactManager::Collide()
> b2Contact::GetFixtureA()
Does anyone have an idea why this is happening? Because I tried everything, even pointless stuff like converting all sorts of variables to pointers and back (Mainly the b2Body-assiociated variables, which aren't in the example since it doesnt even work without them anyways.)
Kind regards