Skip to content

Commit

Permalink
Fix for issue 407. Reverted a previous bad fix. Also ran Visual Studi…
Browse files Browse the repository at this point in the history
…o static analysis and fixed a couple things.
  • Loading branch information
erincatto committed May 12, 2016
1 parent 624f6f9 commit 76fe384
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@
imgui.ini
**/xcshareddata
*.ini
*.lastcodeanalysissucceeded
5 changes: 5 additions & 0 deletions Box2D/Box2D/Collision/Shapes/b2ChainShape.cpp
Expand Up @@ -37,6 +37,11 @@ void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
{
b2Assert(m_vertices == NULL && m_count == 0);
b2Assert(count >= 3);
if (count < 3)
{
return;
}

for (int32 i = 1; i < count; ++i)
{
b2Vec2 v1 = vertices[i-1];
Expand Down
7 changes: 2 additions & 5 deletions Box2D/Box2D/Dynamics/Contacts/b2ContactSolver.cpp
Expand Up @@ -24,6 +24,7 @@
#include <Box2D/Dynamics/b2World.h>
#include <Box2D/Common/b2StackAllocator.h>

// Solver debugging is normally disabled because the block solver sometimes has to deal with a poorly conditioned effective mass matrix.
#define B2_DEBUG_SOLVER 0

bool g_blockSolve = true;
Expand Down Expand Up @@ -375,7 +376,7 @@ void b2ContactSolver::SolveVelocityConstraints()
// Block solver developed in collaboration with Dirk Gregorius (back in 01/07 on Box2D_Lite).
// Build the mini LCP for this contact patch
//
// vn = A * x + b, vn >= 0, , vn >= 0, x >= 0 and vn_i * x_i = 0 with i = 1..2
// vn = A * x + b, vn >= 0, x >= 0 and vn_i * x_i = 0 with i = 1..2
//
// A = J * W * JT and J = ( -n, -r1 x n, n, r2 x n )
// b = vn0 - velocityBias
Expand Down Expand Up @@ -483,10 +484,8 @@ void b2ContactSolver::SolveVelocityConstraints()
//
x.x = - cp1->normalMass * b.x;
x.y = 0.0f;
#if B2_DEBUG_SOLVER == 1
vn1 = 0.0f;
vn2 = vc->K.ex.y * x.x + b.y;
#endif
if (x.x >= 0.0f && vn2 >= 0.0f)
{
// Get the incremental impulse
Expand Down Expand Up @@ -526,10 +525,8 @@ void b2ContactSolver::SolveVelocityConstraints()
//
x.x = 0.0f;
x.y = - cp2->normalMass * b.y;
#if B2_DEBUG_SOLVER == 1
vn1 = vc->K.ey.x * x.y + b.x;
vn2 = 0.0f;
#endif

if (x.y >= 0.0f && vn1 >= 0.0f)
{
Expand Down
7 changes: 6 additions & 1 deletion Box2D/Box2D/Dynamics/b2Body.cpp
Expand Up @@ -213,6 +213,11 @@ b2Fixture* b2Body::CreateFixture(const b2Shape* shape, float32 density)

void b2Body::DestroyFixture(b2Fixture* fixture)
{
if (fixture == nullptr)

This comment has been minimized.

Copy link
@louis-langholtz

louis-langholtz May 16, 2016

I prefer the style of if (!fixture) (over if (fixture == 0-indicator)). Then there's no dependency on the 0-indicator having to be defined as expected either.

This comment has been minimized.

Copy link
@dagostinelli

dagostinelli Jun 5, 2016

It's also a C11 thing. The rest of the library doesn't need C11 support. Please revert to testing for zero.

mkdir buildhere
cd buildhere
cmake ..
make

The error is:

Box2D/Box2D/Box2D/Dynamics/b2Body.cpp:216:17: error: ‘nullptr’ was not declared in this scope
  if (fixture == nullptr)

It can be fixed if the user remembers to specify C11 at the command line:
cmake -DCMAKE_CXX_FLAGS="-std=c++0x" ..

But it's probably best not to introduce this C++ feature for something like this..

{
return;
}

b2Assert(m_world->IsLocked() == false);
if (m_world->IsLocked() == true)
{
Expand Down Expand Up @@ -266,9 +271,9 @@ void b2Body::DestroyFixture(b2Fixture* fixture)
fixture->DestroyProxies(broadPhase);
}

fixture->Destroy(allocator);
fixture->m_body = NULL;
fixture->m_next = NULL;
fixture->Destroy(allocator);
fixture->~b2Fixture();
allocator->Free(fixture, sizeof(b2Fixture));

Expand Down

0 comments on commit 76fe384

Please sign in to comment.