You can't remove bodies during the execution of b2World::Step
. You have to store the list of bodies you want to remove and actually remove them when Step exits.
Example (C++):
//in contact handling:
m_bodiesToRemove.push_back(my_body);
//after Step:
for (b2Body *b : m_bodiesToRemove):
m_world->DestroyBody(b);