diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-21 11:28:02 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-21 11:28:02 +0100 |
commit | 7b622ce6e8a40508dbfccb21380e5f0b2dd45fac (patch) | |
tree | 633abb4f920e5a365b8b781e5d6cbc91734b92f9 /scene/2d/collision_object_2d.cpp | |
parent | d45af488c47a1ed1812e5b6c5c01beee4890e250 (diff) | |
parent | 398e73c689e8506933a066c6a8045a50f58d0c04 (diff) | |
download | redot-engine-7b622ce6e8a40508dbfccb21380e5f0b2dd45fac.tar.gz |
Merge pull request #71021 from reduz/prevent-physics-callback-removal
Error when removing a physics node during a physics callback
Diffstat (limited to 'scene/2d/collision_object_2d.cpp')
-rw-r--r-- | scene/2d/collision_object_2d.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index b2fee6ad82..caea753d99 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -94,10 +94,14 @@ void CollisionObject2D::_notification(int p_what) { bool disabled = !is_enabled(); if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { - if (area) { - PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); + if (callback_lock > 0) { + ERR_PRINT("Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead."); } else { - PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + if (area) { + PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); + } else { + PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + } } } @@ -225,10 +229,14 @@ void CollisionObject2D::_apply_disabled() { switch (disable_mode) { case DISABLE_MODE_REMOVE: { if (is_inside_tree()) { - if (area) { - PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); + if (callback_lock > 0) { + ERR_PRINT("Disabling a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Disable with call_deferred() instead."); } else { - PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + if (area) { + PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); + } else { + PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + } } } } break; |