I'm having a problem where this error crashes my game :
Exception thrown at 0x00CFA4C4 in SDL_Game.exe: 0xC0000005: Access violation reading location 0x0000000C.
It appears this Box2D line (in my code) is causing this error :
body = World::GetWorld()->CreateBody(&bodyDef);
I know that GetWorld returns a valid pointer, so that's not the problem, however the error also leads me to a Box2D source file (b2BlockAllocator.cpp, line 112) :
if (m_freeLists[index])
{
b2Block* block = m_freeLists[index];
m_freeLists[index] = block->next;
return block;
}
And when checking the values of m_freeLists it tells me :
Unable to read memory
This is how I created all the Box2D fitures, bodies etc :
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(x, y);
body = World::GetWorld()->CreateBody(&bodyDef); // <--- Error here :(
shape.SetAsBox(size.x, size.y);
fixtureDef.shape = &shape;
fixtureDef.density = density;
fixtureDef.friction = friction;
body->CreateFixture(&fixtureDef);
I never remove / free any of these variables in my code at all, so that's not whats causing the error)
I'm not sure what else to add here since that's And here's what my b2World looks like :
b2_world = new b2World(gravity);
And the GetWorld function :
b2World* World::GetWorld()
{
return b2_world;
}
I'm not sure what else to add, that's pretty much all Box2D code I have except for stepping the world.