ShapeDef copy "bug?"

I thought this was a bug in our Java port, but I just looked through the C++ version and I see it there, too. I'm not sure, though, this might be expected behavior, just wanted to ask.

The issue is that when you add a shape to a bodydef, instead of the shape definition being copied, a pointer is stored instead. This means that you can't reuse the shapedef within the same bodydef because any changes will corrupt the already-placed shapes (though it is okay to reuse once the body has actually been created).

I can't think of a good reason why shapedefs should not be reusable but bodydefs should be, but let me know if this is, in fact, the desired behavior. If not, the fix is simple, just create a copy of the shapedef in AddShape instead of saving the pointer.
That's going to potentially be a problem when Box2D starts supporting lines segment soups where each shape definition potentially has a lot of data. For small shapes, you can copy them yourself on the stack.

In general, Box2D doesn't duplicate definitions. It only absorbs the data from them.
That makes sense, thanks for the explanation.

I thought I had read something in the docs about copying, but on a second look all I could find was: "Box2D does not keep a reference to the shape or body definitions. It copies the data into the b2Body structure." - but now that I think about it, this is actually correct, I just misinterpreted it.

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