When edge shapes where added to Box2D the signature of b2Body::CreateShape change. Its parameter used to a const b2ShapeDef*, now it has lost the const. I don't know why this was, and the change broke a lot of my code using Box2D, the const change was quite traumatic.
I think it should be reverted back. I've included a patch that shows my few changes (3 lines).
On a side note: When I first attempted the change, I just change the signature back to const and compile. The thought was that I'd then jump in and change whatever else was needed based on compiler warnings and errors. Surprisingly, box2d compiled and ran fine. The C-Cast used to convert the ShapeDef* to a b2EdgeChainDef* is a bit over zealous and casts away the const as well. Just one more reason to prefer C++-Casts over C-Casts.
The diff:
I think it should be reverted back. I've included a patch that shows my few changes (3 lines).
On a side note: When I first attempted the change, I just change the signature back to const and compile. The thought was that I'd then jump in and change whatever else was needed based on compiler warnings and errors. Surprisingly, box2d compiled and ran fine. The C-Cast used to convert the ShapeDef* to a b2EdgeChainDef* is a bit over zealous and casts away the const as well. Just one more reason to prefer C++-Casts over C-Casts.
The diff:
Code:
Index: Source/Dynamics/b2Body.cpp
===================================================================
--- Source/Dynamics/b2Body.cpp (revision 190)
+++ Source/Dynamics/b2Body.cpp (working copy)
@@ -128,7 +128,7 @@
return angle2;
}
-b2Shape* b2Body::CreateShape(b2ShapeDef* def)
+b2Shape* b2Body::CreateShape( const b2ShapeDef* def)
{
b2Assert(m_world->m_lock == false);
if (m_world->m_lock == true)
@@ -141,7 +141,7 @@
// return more than one shape to add to parent body... maybe it should add
// shapes directly to the body instead of returning them?)
if (def->type == e_edgeShape) {
- b2EdgeChainDef* edgeDef = (b2EdgeChainDef*)def;
+ const b2EdgeChainDef* edgeDef = static_cast<const b2EdgeChainDef*>(def);
b2Vec2 v1;
b2Vec2 v2;
int i;
Index: Source/Dynamics/b2Body.h
===================================================================
--- Source/Dynamics/b2Body.h (revision 190)
+++ Source/Dynamics/b2Body.h (working copy)
@@ -104,7 +104,7 @@
/// Creates a shape and attach it to this body.
/// @param shapeDef the shape definition.
/// @warning This function is locked during callbacks.
- b2Shape* CreateShape(b2ShapeDef* shapeDef);
+ b2Shape* CreateShape( const b2ShapeDef* shapeDef);
/// Destroy a shape. This removes the shape from the broad-phase and
/// therefore destroys any contacts associated with this shape. All shapes
===================================================================
--- Source/Dynamics/b2Body.cpp (revision 190)
+++ Source/Dynamics/b2Body.cpp (working copy)
@@ -128,7 +128,7 @@
return angle2;
}
-b2Shape* b2Body::CreateShape(b2ShapeDef* def)
+b2Shape* b2Body::CreateShape( const b2ShapeDef* def)
{
b2Assert(m_world->m_lock == false);
if (m_world->m_lock == true)
@@ -141,7 +141,7 @@
// return more than one shape to add to parent body... maybe it should add
// shapes directly to the body instead of returning them?)
if (def->type == e_edgeShape) {
- b2EdgeChainDef* edgeDef = (b2EdgeChainDef*)def;
+ const b2EdgeChainDef* edgeDef = static_cast<const b2EdgeChainDef*>(def);
b2Vec2 v1;
b2Vec2 v2;
int i;
Index: Source/Dynamics/b2Body.h
===================================================================
--- Source/Dynamics/b2Body.h (revision 190)
+++ Source/Dynamics/b2Body.h (working copy)
@@ -104,7 +104,7 @@
/// Creates a shape and attach it to this body.
/// @param shapeDef the shape definition.
/// @warning This function is locked during callbacks.
- b2Shape* CreateShape(b2ShapeDef* shapeDef);
+ b2Shape* CreateShape( const b2ShapeDef* shapeDef);
/// Destroy a shape. This removes the shape from the broad-phase and
/// therefore destroys any contacts associated with this shape. All shapes