2.0 Progress Update

Erin Catto wrote:
That's a bug (obviously I haven't tested that function yet).

Try changing NULL to this.


Ahh, thanks. At this point would you appreciate bug reports around these untested functions, or would you rather we wait for some sort of RC version?
Bug reports are good. Also, this is a good thread for them. That way I know the bug is for the SVN version.

I'm almost feature complete for 2.0. Then only examples and documentation remains.
Attempting to remove a shape from a body that's resting against another body causes a NULL dereference attempt as the contacts are cleaned up: (this is against SVN revision 97)

Code:
b2AABB aabb;
aabb.lowerBound.Set(-100, -100);
aabb.upperBound.Set(100, 100);
b2World w(aabb, b2Vec2(0, -10), true);

b2BodyDef bodydef;
bodydef.type = b2BodyDef::e_dynamicBody;
bodydef.position.Set(0, 0);
b2Body * body = w.Create(&bodydef);

b2PolygonDef boxdef;
boxdef.SetAsBox(1, 1, b2Vec2(0, 0), 0);
boxdef.density = 1;
body->Create(&boxdef);
boxdef.SetAsBox(1, 1, b2Vec2(1, 0), 0);
b2Shape * shape = body->Create(&boxdef);
body->SetMassFromShapes();

bodydef.type = b2BodyDef::e_staticBody;
bodydef.position.Set(0, -10);
b2Body * ground = w.Create(&bodydef);
boxdef.SetAsBox(100, 1, b2Vec2(0, 0), 0);
boxdef.density = 0;
ground->Create(&boxdef);
ground->SetMassFromShapes();

for (int i = 0; i < 500; i ++) {
    w.Step(0.3f, 100);

    if (i == 20) // b2ContactManager.cpp:189 can't derefence a NULL body1
        body->Destroy(shape); // boom
    TCHAR szDebug[100];
    _stprintf_s(szDebug, _T("%d %f %f\n"), i,
        body->GetWorldCenter().x, body->GetWorldCenter().y);
    OutputDebugString(szDebug);
}
It looks like simply moving the DestroyProxy call up to before the shape's data structures are cleared out fixes this. At least the bugs I'm finding now are all in my code 🙂

Code:
==== Dynamics/b2Body.cpp ====
171c171,173
<       s->m_body = NULL;
---
>       s->DestroyProxy(m_world->m_broadPhase);
>
>     s->m_body = NULL;
195d196
<       s->DestroyProxy(m_world->m_broadPhase);


Also, this simple change will make VC happier in a release build:

Code:
==== Collision/Shapes/b2PolygonShape.cpp ====
107,108c107
<       float32 length = ux.Normalize();
<       b2Assert(length > FLT_EPSILON);
---
>       b2Assert(ux.Normalize() > FLT_EPSILON);
Thanks for the crash report. I fixed the crash and added a shape editing test.

I've switched to using warning level 3 in release to avoid the warnings that occur when assertions are removed by the preprocessor.
Erin, you might want to take a look at this article on the proper way to write an assert macro. I know what you're probably thinking, "there's a proper way?" Actually, I was pretty surprised just how much better that assert is over the default.

The end result is that you'll be able to go back to w4.
Thanks for the link. I'll look into it.

In other news, 2.0 is now feature complete! Continuous physics seems to be working well now and it finishes the time step so there is no visual lag. You can add/delete shapes from a body and you can use sensors for non-solid collision. Now I mainly have documentation work to complete.
My hat and the top half of my head goes off to you, Erin, the amount of work you've put into Box2D is staggering to say the least.

Thanks for all the time and effort 😁
I am liking the sensor example 😀 There are so many amazing features in 2.0, I just hope I can keep up with finding ways to use them in my games! When I look at the planned features past 2.0...wow...spline joints, meshes, etc.. I don't even know what some of it is: tree constraints, static point-grids? 😮 I need to go look those up... Ok tree constraints appear to be some type of memory management thing, but it sounds cool!

If I am able to attain my crazy goal of making a living off of Flash games, I will owe you not only my deepest gratitude, but my job! 😮 (ok before anyone calls me crazy, the guys over at http://handdrawngames.com did it, and they didn't even have Box2D!) Of course if it doesn't work out I will be the most knowledgeable Box2D user living on the streets... Ok actually I will probably end up in a cubicle, but I'm not sure which is worse! Ah, such is the life of a recent CS college grad...
Static point grids...

Erin, if I were to say Cortex Command, would I be thinking along the right track?

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