Strange Query Behavior

I've got some code that's giving me rather strange results. I'm not quite sure yet if it's a fault on my end, or a bug in Box2D.

I have an editor that lets you draw polygons. When you right click on one of them, it calls this function (where p is your mouse position)

Code:
void Editor::DestroyPoly(b2Vec2 p) // buggy!!
{
   // Make a small box.
   b2AABB aabb;
   b2Vec2 d;
   d.Set(0.001f, 0.001f);
   aabb.minVertex = p - d;
   aabb.maxVertex = p + d;

   // Query the world for overlapping shapes.
   const int32 k_maxCount = 10;
   b2Shape* shapes[k_maxCount];
   int32 count = m_world->Query(aabb, shapes, k_maxCount);
   b2Body* body = NULL;
   printf("%d\n",count);
   for (int32 i = 0; i < count; ++i)
   {
      bool inside = shapes[i]->TestPoint(p);
      if (inside)
      {
         body = shapes[i]->m_body;
         //m_bodies.erase(*(list<b2BodyDef>::const_iterator*)body->m_userData);
         //delete (list<b2BodyDef>::const_iterator*)body->m_userData;
         printf("destroying body\n");
         m_world->DestroyBody(body);
         break;
      }
   }
}


If I draw one triangle, and then delete it, it disappears as expected, but if I click again, the Query still returns a count of 1, even though the object is gone, and it prints "destroying body" again. The two commented lines commented out above cause my program to crash when deleting a body that's already been deleted.

I'm drawing the shapes like this

Code:
   // draw other shapes
   for (b2Body* b = m_world->m_bodyList; b; b = b->m_next)
   {   
      for (b2Shape* s = b->m_shapeList; s; s = s->m_next)
      {
         drawShape(s, Color(0,1,0));
      }
   }


Which directly uses the b2Bodies. If the shape is absent from the drawing algorithm, shouldn't it also be destroyed from the queries?

Edit: I'm using Box2D 1.4.3
Your code looks fine.

This result suggests that the shape proxy is not being destroyed properly in the broad-phase. Look at the TestBed code where it prints out the proxy count. See if it changes in your code when you destroy the body.

Are you holding a reference to the destoyed body somewhere else in your code?

If you don't find the problem, please try to create a testbed example that causes the crash.
I tried recreating my delete feature in the test bed, using as little code as possible to avoid introducing new errors. Seems to work fine there, and the count (and proxies) are properly decremented (makes a nice edition to the test bed too! snapping the bridge in half was fun)

Must be something wrong in my code. I'll have to look into it some more.
Found the problem. The simulation wasn't running; I wasn't stepping. It seems you remove the body immediately after it's destroyed, but not the shapes until the next time step. Created a bit of confusion there!
Yeah, body destruction is defered in 1.4.3. This is gone in 2.0. Too many headaches (like this one). Sorry for the confusion.

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