destroy body - possible bug

I have a list of bodies consisting of m_mass 1.5 and say 1.0.

When I did the following:

for (b2Body* b = m_world->m_bodyList; b; b = b->m_next)
{
if (b->m_mass == 1.5f){
m_world->DestroyBody(b);
}
}

It destroys all my bodies instead of the ones with 1.5 only.
You can't destroy a body and then use it's next pointer. Instead write your code like this:

Code:
b2Body* b = m_world->GetBodyList();
while (b)
{
  b2Body* b0 = b;
  b = b->GetNext();
  if (b0->GetMass() == 1.5f)
  {
     m_world->Destroy(b0);
     b0 = NULL;
  }
}
ok thanks. another one of those pointer headaches.

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