Box2d Crashing

Hey all,
Just go box2d up and running, love it. I am running into a very strange bug.

When I add shapes slowly it works great, once i start adding a ton of shapes it freezes up. I have no idea, why. This is one of the errors that I have found.
Code:
b2PolygonShape.cpp:224: failed assertion `d.x >= 0.0f'


any help would be great.

Thanks,
T
Can you reproduce the behaviour in a testbed example? That will make it far easier for people to help diagnose the problem.

Bill
The comment on the line above says: "Your shape has a radius/extent less than b2_toiSlop."
yes in the pyramid example if i add more shapes to the loop it crashes. The code below is int Pyramid.h normally there are 25 shapes make it 80 or something larger and you will get a crash. Im working on a mac osx intel.


This code will break
Code:
b2PolygonDef sd;
float32 a = 0.5f;
sd.SetAsBox(a, a);
sd.density = 5.0f;

b2Vec2 x(-10.0f, 0.75f);
b2Vec2 y;
b2Vec2 deltaX(0.5625f, 2.0f);
b2Vec2 deltaY(1.125f, 0.0f);

for (int32 i = 0; i < 65; ++i) {
   y = x;
for (int32 j = i; j < 65; ++j)

            {
b2BodyDef bd;
bd.position = y;
b2Body* body = m_world->CreateBody(&bd);
body->CreateShape(&sd);
body->SetMassFromShapes();
y += deltaY;

   }
x += deltaX;
}
That's a separate issue from the assertion you hit in your first post - setting the bottom row to be 80 wide means you're creating 80 + 79 + 78 + ... + 1 = ( 80 * 79 ) / 2 (somewhere around 3200) shapes, which is a huge number, and Box2d by default does not allow that many shapes (I think the default is 512, though I could be remembering wrong). In b2Settings.h you can change the max proxies to allow more, but I doubt if having that many shapes in the simulation is a good idea for performance reasons (especially stacked as in the pyramid demo!).
I just encountered this error, luckily I was able to quickly pinpoint the cause.

I think the default minimum number of proxies should be a bit larger than 512. On my machine, a square stack of 20x25 (500) boxes simulates at almost 100fps.

Is there some sort of performance impact of increasing b2_maxProxies (and b2_maxPairs)? I can see that it helps reduce the memory footprint.

Similarly, scanning through b2Settings.h I noticed maxLinearVelocity and maxAngularVelocity being set to some not-very-huge constants (200 and 250). If I'm going to simulate actual bullets, I would want this to be quite a bit higher. Would it introduce too many numerical problems if I increased the max linear velocity to, say, 1000 or 2000?
dc443 wrote:
Similarly, scanning through b2Settings.h I noticed maxLinearVelocity and maxAngularVelocity being set to some not-very-huge constants (200 and 250). If I'm going to simulate actual bullets, I would want this to be quite a bit higher. Would it introduce too many numerical problems if I increased the max linear velocity to, say, 1000 or 2000?
and

Those velocity maximums are 200m/sec and 250m/sec respectively. Quite fast 😉 It's certainly ok to experiment with changing the settings, but the engine is "best" within certain ranges. You might want to reassess your scaling factor and adjust that instead of these velocities.

Bill
the2bears wrote:
Those velocity maximums are 200m/sec and 250m/sec respectively. Quite fast 😉

Indeed - as a point of reference, the speed of sound is 340.29 m/s according to Google.

If that's not fast enough for you, you're either a) using pixel units, which is Bad, or b) doing some pretty hardcore stuff with the engine, in which case you'll probably need to be tweaking a lot of those settings for your particular use case.
How fast do the "bomb" projectiles travel in the TestBed?

I think it would be very nice to have a sort of high speed weapon that is based on the CCD capabilities of the Box2D engine. It just doesn't seem right that you'd limit the velocities while add support for correctly handling extremely high-velocity collisions. But I understand. I'll definitely do some testing, I doubt I'll use super fast projectiles anyway. It just seemed to me that 200 m/s isn't such an astronomical value... I can definitely envision someone trying to make a "realistic" shooter game with "realistic" bullet speeds (which generally are supersonic). Most games either make guns hit their targets instantly, or the bullets end up being usually an order of magnitude slower than in real life.
dc443 wrote:
How fast do the "bomb" projectiles travel in the TestBed?

I think it would be very nice to have a sort of high speed weapon that is based on the CCD capabilities of the Box2D engine. It just doesn't seem right that you'd limit the velocities while add support for correctly handling extremely high-velocity collisions. But I understand. I'll definitely do some testing, I doubt I'll use super fast projectiles anyway. It just seemed to me that 200 m/s isn't such an astronomical value... I can definitely envision someone trying to make a "realistic" shooter game with "realistic" bullet speeds (which generally are supersonic). Most games either make guns hit their targets instantly, or the bullets end up being usually an order of magnitude slower than in real life.


I'm making a shooter, and these speeds are absolutely fast enough. In fact I can't think of any shooter (and I know a bit about them) that would need faster. I don't believe you're yet thinking of how to properly scale the physics world to the rendered one. My viewable play area is 80x60 in Box2D units, which I scale to render in an 800x600 window. With this scaling factor, a bullet can go across the screen in roughly 1/3 of a second... and I could scale things even further if I needed to.

edit: I see we might be talking about different "shooter" types 🙂 So get what wisdom you can from my comments.

Bill

Original thread: https://box2d.org/forum/viewtopic.php?t=810