From 89ce63a84f1f98f4b5b31d0bbe13588c249b923a Mon Sep 17 00:00:00 2001 From: Ricardo Buring Date: Fri, 25 Feb 2022 14:21:55 +0100 Subject: [PATCH] AreaSW and Area2DSW: fix premature return in call_queries --- servers/physics/area_sw.cpp | 106 +++++++++++++++--------------- servers/physics_2d/area_2d_sw.cpp | 106 +++++++++++++++--------------- 2 files changed, 104 insertions(+), 108 deletions(-) diff --git a/servers/physics/area_sw.cpp b/servers/physics/area_sw.cpp index 37157ba9717..c9c2dae6c82 100644 --- a/servers/physics/area_sw.cpp +++ b/servers/physics/area_sw.cpp @@ -200,76 +200,74 @@ void AreaSW::set_monitorable(bool p_monitorable) { void AreaSW::call_queries() { if (monitor_callback_id && !monitored_bodies.empty()) { - Variant res[5]; - Variant *resptr[5]; - for (int i = 0; i < 5; i++) { - resptr[i] = &res[i]; - } - Object *obj = ObjectDB::get_instance(monitor_callback_id); - if (!obj) { - monitored_bodies.clear(); - monitor_callback_id = 0; - return; - } + if (obj) { + Variant res[5]; + Variant *resptr[5]; + for (int i = 0; i < 5; i++) { + resptr[i] = &res[i]; + } + + for (Map::Element *E = monitored_bodies.front(); E;) { + if (E->get().state == 0) { // Nothing happened + Map::Element *next = E->next(); + monitored_bodies.erase(E); + E = next; + continue; + } + + res[0] = E->get().state > 0 ? PhysicsServer::AREA_BODY_ADDED : PhysicsServer::AREA_BODY_REMOVED; + res[1] = E->key().rid; + res[2] = E->key().instance_id; + res[3] = E->key().body_shape; + res[4] = E->key().area_shape; - for (Map::Element *E = monitored_bodies.front(); E;) { - if (E->get().state == 0) { // Nothing happened Map::Element *next = E->next(); monitored_bodies.erase(E); E = next; - continue; + + Variant::CallError ce; + obj->call(monitor_callback_method, (const Variant **)resptr, 5, ce); } - - res[0] = E->get().state > 0 ? PhysicsServer::AREA_BODY_ADDED : PhysicsServer::AREA_BODY_REMOVED; - res[1] = E->key().rid; - res[2] = E->key().instance_id; - res[3] = E->key().body_shape; - res[4] = E->key().area_shape; - - Map::Element *next = E->next(); - monitored_bodies.erase(E); - E = next; - - Variant::CallError ce; - obj->call(monitor_callback_method, (const Variant **)resptr, 5, ce); + } else { + monitored_bodies.clear(); + monitor_callback_id = 0; } } if (area_monitor_callback_id && !monitored_areas.empty()) { - Variant res[5]; - Variant *resptr[5]; - for (int i = 0; i < 5; i++) { - resptr[i] = &res[i]; - } - Object *obj = ObjectDB::get_instance(area_monitor_callback_id); - if (!obj) { - monitored_areas.clear(); - area_monitor_callback_id = 0; - return; - } + if (obj) { + Variant res[5]; + Variant *resptr[5]; + for (int i = 0; i < 5; i++) { + resptr[i] = &res[i]; + } + + for (Map::Element *E = monitored_areas.front(); E;) { + if (E->get().state == 0) { // Nothing happened + Map::Element *next = E->next(); + monitored_areas.erase(E); + E = next; + continue; + } + + res[0] = E->get().state > 0 ? PhysicsServer::AREA_BODY_ADDED : PhysicsServer::AREA_BODY_REMOVED; + res[1] = E->key().rid; + res[2] = E->key().instance_id; + res[3] = E->key().body_shape; + res[4] = E->key().area_shape; - for (Map::Element *E = monitored_areas.front(); E;) { - if (E->get().state == 0) { // Nothing happened Map::Element *next = E->next(); monitored_areas.erase(E); E = next; - continue; + + Variant::CallError ce; + obj->call(area_monitor_callback_method, (const Variant **)resptr, 5, ce); } - - res[0] = E->get().state > 0 ? PhysicsServer::AREA_BODY_ADDED : PhysicsServer::AREA_BODY_REMOVED; - res[1] = E->key().rid; - res[2] = E->key().instance_id; - res[3] = E->key().body_shape; - res[4] = E->key().area_shape; - - Map::Element *next = E->next(); - monitored_areas.erase(E); - E = next; - - Variant::CallError ce; - obj->call(area_monitor_callback_method, (const Variant **)resptr, 5, ce); + } else { + monitored_areas.clear(); + area_monitor_callback_id = 0; } } } diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp index 48134fdbaf4..46c0aafc720 100644 --- a/servers/physics_2d/area_2d_sw.cpp +++ b/servers/physics_2d/area_2d_sw.cpp @@ -200,76 +200,74 @@ void Area2DSW::set_monitorable(bool p_monitorable) { void Area2DSW::call_queries() { if (monitor_callback_id && !monitored_bodies.empty()) { - Variant res[5]; - Variant *resptr[5]; - for (int i = 0; i < 5; i++) { - resptr[i] = &res[i]; - } - Object *obj = ObjectDB::get_instance(monitor_callback_id); - if (!obj) { - monitored_bodies.clear(); - monitor_callback_id = 0; - return; - } + if (obj) { + Variant res[5]; + Variant *resptr[5]; + for (int i = 0; i < 5; i++) { + resptr[i] = &res[i]; + } + + for (Map::Element *E = monitored_bodies.front(); E;) { + if (E->get().state == 0) { // Nothing happened + Map::Element *next = E->next(); + monitored_bodies.erase(E); + E = next; + continue; + } + + res[0] = E->get().state > 0 ? Physics2DServer::AREA_BODY_ADDED : Physics2DServer::AREA_BODY_REMOVED; + res[1] = E->key().rid; + res[2] = E->key().instance_id; + res[3] = E->key().body_shape; + res[4] = E->key().area_shape; - for (Map::Element *E = monitored_bodies.front(); E;) { - if (E->get().state == 0) { // Nothing happened Map::Element *next = E->next(); monitored_bodies.erase(E); E = next; - continue; + + Variant::CallError ce; + obj->call(monitor_callback_method, (const Variant **)resptr, 5, ce); } - - res[0] = E->get().state > 0 ? Physics2DServer::AREA_BODY_ADDED : Physics2DServer::AREA_BODY_REMOVED; - res[1] = E->key().rid; - res[2] = E->key().instance_id; - res[3] = E->key().body_shape; - res[4] = E->key().area_shape; - - Map::Element *next = E->next(); - monitored_bodies.erase(E); - E = next; - - Variant::CallError ce; - obj->call(monitor_callback_method, (const Variant **)resptr, 5, ce); + } else { + monitored_bodies.clear(); + monitor_callback_id = 0; } } if (area_monitor_callback_id && !monitored_areas.empty()) { - Variant res[5]; - Variant *resptr[5]; - for (int i = 0; i < 5; i++) { - resptr[i] = &res[i]; - } - Object *obj = ObjectDB::get_instance(area_monitor_callback_id); - if (!obj) { - monitored_areas.clear(); - area_monitor_callback_id = 0; - return; - } + if (obj) { + Variant res[5]; + Variant *resptr[5]; + for (int i = 0; i < 5; i++) { + resptr[i] = &res[i]; + } + + for (Map::Element *E = monitored_areas.front(); E;) { + if (E->get().state == 0) { // Nothing happened + Map::Element *next = E->next(); + monitored_areas.erase(E); + E = next; + continue; + } + + res[0] = E->get().state > 0 ? Physics2DServer::AREA_BODY_ADDED : Physics2DServer::AREA_BODY_REMOVED; + res[1] = E->key().rid; + res[2] = E->key().instance_id; + res[3] = E->key().body_shape; + res[4] = E->key().area_shape; - for (Map::Element *E = monitored_areas.front(); E;) { - if (E->get().state == 0) { // Nothing happened Map::Element *next = E->next(); monitored_areas.erase(E); E = next; - continue; + + Variant::CallError ce; + obj->call(area_monitor_callback_method, (const Variant **)resptr, 5, ce); } - - res[0] = E->get().state > 0 ? Physics2DServer::AREA_BODY_ADDED : Physics2DServer::AREA_BODY_REMOVED; - res[1] = E->key().rid; - res[2] = E->key().instance_id; - res[3] = E->key().body_shape; - res[4] = E->key().area_shape; - - Map::Element *next = E->next(); - monitored_areas.erase(E); - E = next; - - Variant::CallError ce; - obj->call(area_monitor_callback_method, (const Variant **)resptr, 5, ce); + } else { + monitored_areas.clear(); + area_monitor_callback_id = 0; } } }