diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 9e8bf62fc5e..2a225e57977 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -428,8 +428,8 @@ void Area2D::set_monitorable(bool p_enable) { if (locked || (is_inside_tree() && Physics2DServer::get_singleton()->is_flushing_queries())) { ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)"); + ERR_FAIL(); } - ERR_FAIL_COND(locked || Physics2DServer::get_singleton()->is_flushing_queries()); if (p_enable == monitorable) return; diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 9e15a416b25..e58e26d2d10 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -441,8 +441,8 @@ void Area::set_monitorable(bool p_enable) { if (locked || (is_inside_tree() && PhysicsServer::get_singleton()->is_flushing_queries())) { ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)"); + ERR_FAIL(); } - ERR_FAIL_COND(locked || PhysicsServer::get_singleton()->is_flushing_queries()); if (p_enable == monitorable) return; diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 2975ae94537..36d18e8901c 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -40,10 +40,10 @@ #include "joints/pin_joint_sw.h" #include "joints/slider_joint_sw.h" -#define FLUSH_QUERY_CHECK \ - if (flushing_queries) { \ - ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred()/set_deferred() to change monitoring state instead"); \ - ERR_FAIL(); \ +#define FLUSH_QUERY_CHECK(m_object) \ + if (m_object->get_space() && flushing_queries) { \ + ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead"); \ + ERR_FAIL(); \ } RID PhysicsServerSW::shape_create(ShapeType p_shape) { @@ -358,11 +358,10 @@ void PhysicsServerSW::area_clear_shapes(RID p_area) { void PhysicsServerSW::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { - FLUSH_QUERY_CHECK - AreaSW *area = area_owner.get(p_area); ERR_FAIL_COND(!area); ERR_FAIL_INDEX(p_shape_idx, area->get_shape_count()); + FLUSH_QUERY_CHECK(area); area->set_shape_as_disabled(p_shape_idx, p_disabled); } @@ -443,10 +442,9 @@ void PhysicsServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) { void PhysicsServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { - FLUSH_QUERY_CHECK - AreaSW *area = area_owner.get(p_area); ERR_FAIL_COND(!area); + FLUSH_QUERY_CHECK(area); area->set_monitorable(p_monitorable); } @@ -592,11 +590,11 @@ RID PhysicsServerSW::body_get_shape(RID p_body, int p_shape_idx) const { void PhysicsServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - FLUSH_QUERY_CHECK - BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); + FLUSH_QUERY_CHECK(body); + body->set_shape_as_disabled(p_shape_idx, p_disabled); } diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 4d1c56b8439..283d20876de 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -36,8 +36,8 @@ #include "core/project_settings.h" #include "core/script_language.h" -#define FLUSH_QUERY_CHECK \ - if (flushing_queries) { \ +#define FLUSH_QUERY_CHECK(m_object) \ + if (m_object->get_space() && flushing_queries) { \ ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead"); \ ERR_FAIL(); \ } @@ -410,12 +410,11 @@ void Physics2DServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, co void Physics2DServerSW::area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) { - FLUSH_QUERY_CHECK - Area2DSW *area = area_owner.get(p_area); ERR_FAIL_COND(!area); - ERR_FAIL_INDEX(p_shape, area->get_shape_count()); + FLUSH_QUERY_CHECK(area); + area->set_shape_as_disabled(p_shape, p_disabled); } @@ -550,10 +549,9 @@ void Physics2DServerSW::area_set_pickable(RID p_area, bool p_pickable) { void Physics2DServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { - FLUSH_QUERY_CHECK - Area2DSW *area = area_owner.get(p_area); ERR_FAIL_COND(!area); + FLUSH_QUERY_CHECK(area); area->set_monitorable(p_monitorable); } @@ -630,10 +628,9 @@ RID Physics2DServerSW::body_get_space(RID p_body) const { void Physics2DServerSW::body_set_mode(RID p_body, BodyMode p_mode) { - FLUSH_QUERY_CHECK - Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); + FLUSH_QUERY_CHECK(body); body->set_mode(p_mode); }; @@ -734,12 +731,10 @@ void Physics2DServerSW::body_clear_shapes(RID p_body) { void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - FLUSH_QUERY_CHECK - Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); - ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); + FLUSH_QUERY_CHECK(body); body->set_shape_as_disabled(p_shape_idx, p_disabled); } @@ -747,8 +742,8 @@ void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_sh Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); - ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); + FLUSH_QUERY_CHECK(body); body->set_shape_as_one_way_collision(p_shape_idx, p_enable, p_margin); }