mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
Remove elements from monitored_bodies and monitored_areas as they are
processed before calling the callback, instead of after they have all been processed, because the callbacks may readd them.
This commit is contained in:
parent
8ccb1cec91
commit
7eb0fcdb1a
@ -213,9 +213,10 @@ void Area2DSW::call_queries() {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E; E = E->next()) {
|
||||
if (E->get().state == 0) {
|
||||
continue; //nothing happened
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E;) {
|
||||
if (E->get().state == 0) { // Nothing happened
|
||||
E = E->next();
|
||||
continue;
|
||||
}
|
||||
|
||||
res[0] = E->get().state > 0 ? PhysicsServer2D::AREA_BODY_ADDED : PhysicsServer2D::AREA_BODY_REMOVED;
|
||||
@ -224,13 +225,15 @@ void Area2DSW::call_queries() {
|
||||
res[3] = E->key().body_shape;
|
||||
res[4] = E->key().area_shape;
|
||||
|
||||
Map<BodyKey, BodyState>::Element *next = E->next();
|
||||
monitored_bodies.erase(E);
|
||||
E = next;
|
||||
|
||||
Callable::CallError ce;
|
||||
obj->call(monitor_callback_method, (const Variant **)resptr, 5, ce);
|
||||
}
|
||||
}
|
||||
|
||||
monitored_bodies.clear();
|
||||
|
||||
if (area_monitor_callback_id.is_valid() && !monitored_areas.empty()) {
|
||||
Variant res[5];
|
||||
Variant *resptr[5];
|
||||
@ -245,9 +248,10 @@ void Area2DSW::call_queries() {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E; E = E->next()) {
|
||||
if (E->get().state == 0) {
|
||||
continue; //nothing happened
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E;) {
|
||||
if (E->get().state == 0) { // Nothing happened
|
||||
E = E->next();
|
||||
continue;
|
||||
}
|
||||
|
||||
res[0] = E->get().state > 0 ? PhysicsServer2D::AREA_BODY_ADDED : PhysicsServer2D::AREA_BODY_REMOVED;
|
||||
@ -256,14 +260,14 @@ void Area2DSW::call_queries() {
|
||||
res[3] = E->key().body_shape;
|
||||
res[4] = E->key().area_shape;
|
||||
|
||||
Map<BodyKey, BodyState>::Element *next = E->next();
|
||||
monitored_areas.erase(E);
|
||||
E = next;
|
||||
|
||||
Callable::CallError ce;
|
||||
obj->call(area_monitor_callback_method, (const Variant **)resptr, 5, ce);
|
||||
}
|
||||
}
|
||||
|
||||
monitored_areas.clear();
|
||||
|
||||
//get_space()->area_remove_from_monitor_query_list(&monitor_query_list);
|
||||
}
|
||||
|
||||
Area2DSW::Area2DSW() :
|
||||
|
@ -213,9 +213,10 @@ void Area3DSW::call_queries() {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E; E = E->next()) {
|
||||
if (E->get().state == 0) {
|
||||
continue; //nothing happened
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E;) {
|
||||
if (E->get().state == 0) { // Nothing happened
|
||||
E = E->next();
|
||||
continue;
|
||||
}
|
||||
|
||||
res[0] = E->get().state > 0 ? PhysicsServer3D::AREA_BODY_ADDED : PhysicsServer3D::AREA_BODY_REMOVED;
|
||||
@ -224,13 +225,15 @@ void Area3DSW::call_queries() {
|
||||
res[3] = E->key().body_shape;
|
||||
res[4] = E->key().area_shape;
|
||||
|
||||
Map<BodyKey, BodyState>::Element *next = E->next();
|
||||
monitored_bodies.erase(E);
|
||||
E = next;
|
||||
|
||||
Callable::CallError ce;
|
||||
obj->call(monitor_callback_method, (const Variant **)resptr, 5, ce);
|
||||
}
|
||||
}
|
||||
|
||||
monitored_bodies.clear();
|
||||
|
||||
if (area_monitor_callback_id.is_valid() && !monitored_areas.empty()) {
|
||||
Variant res[5];
|
||||
Variant *resptr[5];
|
||||
@ -245,9 +248,10 @@ void Area3DSW::call_queries() {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E; E = E->next()) {
|
||||
if (E->get().state == 0) {
|
||||
continue; //nothing happened
|
||||
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E;) {
|
||||
if (E->get().state == 0) { // Nothing happened
|
||||
E = E->next();
|
||||
continue;
|
||||
}
|
||||
|
||||
res[0] = E->get().state > 0 ? PhysicsServer3D::AREA_BODY_ADDED : PhysicsServer3D::AREA_BODY_REMOVED;
|
||||
@ -256,13 +260,14 @@ void Area3DSW::call_queries() {
|
||||
res[3] = E->key().body_shape;
|
||||
res[4] = E->key().area_shape;
|
||||
|
||||
Map<BodyKey, BodyState>::Element *next = E->next();
|
||||
monitored_areas.erase(E);
|
||||
E = next;
|
||||
|
||||
Callable::CallError ce;
|
||||
obj->call(area_monitor_callback_method, (const Variant **)resptr, 5, ce);
|
||||
}
|
||||
}
|
||||
|
||||
monitored_areas.clear();
|
||||
//get_space()->area_remove_from_monitor_query_list(&monitor_query_list);
|
||||
}
|
||||
|
||||
Area3DSW::Area3DSW() :
|
||||
|
Loading…
Reference in New Issue
Block a user