diff --git a/servers/physics/area_sw.cpp b/servers/physics/area_sw.cpp index 562b9c42ab4..3428ee74281 100644 --- a/servers/physics/area_sw.cpp +++ b/servers/physics/area_sw.cpp @@ -192,7 +192,9 @@ void AreaSW::call_queries() { for (Map::Element *E = monitored_bodies.front(); E;) { if (E->get().state == 0) { // Nothing happened - E = E->next(); + Map::Element *next = E->next(); + monitored_bodies.erase(E); + E = next; continue; } @@ -228,7 +230,9 @@ void AreaSW::call_queries() { for (Map::Element *E = monitored_areas.front(); E;) { if (E->get().state == 0) { // Nothing happened - E = E->next(); + Map::Element *next = E->next(); + monitored_areas.erase(E); + E = next; continue; } diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp index c216b9fb364..bd97f055467 100644 --- a/servers/physics_2d/area_2d_sw.cpp +++ b/servers/physics_2d/area_2d_sw.cpp @@ -192,7 +192,9 @@ void Area2DSW::call_queries() { for (Map::Element *E = monitored_bodies.front(); E;) { if (E->get().state == 0) { // Nothing happened - E = E->next(); + Map::Element *next = E->next(); + monitored_bodies.erase(E); + E = next; continue; } @@ -228,7 +230,9 @@ void Area2DSW::call_queries() { for (Map::Element *E = monitored_areas.front(); E;) { if (E->get().state == 0) { // Nothing happened - E = E->next(); + Map::Element *next = E->next(); + monitored_areas.erase(E); + E = next; continue; }