diff --git a/modules/godot_physics_2d/godot_body_2d.h b/modules/godot_physics_2d/godot_body_2d.h index aa7ba844485..bcb55c6d323 100644 --- a/modules/godot_physics_2d/godot_body_2d.h +++ b/modules/godot_physics_2d/godot_body_2d.h @@ -181,6 +181,7 @@ public: } _FORCE_INLINE_ void set_max_contacts_reported(int p_size) { + ERR_FAIL_INDEX(p_size, MAX_CONTACTS_REPORTED_2D_MAX); contacts.resize(p_size); contact_count = 0; if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC && p_size) { diff --git a/modules/godot_physics_3d/godot_body_3d.h b/modules/godot_physics_3d/godot_body_3d.h index 779480f80d0..7dcd17b1921 100644 --- a/modules/godot_physics_3d/godot_body_3d.h +++ b/modules/godot_physics_3d/godot_body_3d.h @@ -175,6 +175,7 @@ public: } _FORCE_INLINE_ void set_max_contacts_reported(int p_size) { + ERR_FAIL_INDEX(p_size, MAX_CONTACTS_REPORTED_3D_MAX); contacts.resize(p_size); contact_count = 0; if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC && p_size) { diff --git a/modules/jolt_physics/objects/jolt_body_3d.cpp b/modules/jolt_physics/objects/jolt_body_3d.cpp index f94b7eff458..9e5c437f972 100644 --- a/modules/jolt_physics/objects/jolt_body_3d.cpp +++ b/modules/jolt_physics/objects/jolt_body_3d.cpp @@ -881,7 +881,7 @@ void JoltBody3D::set_center_of_mass_custom(const Vector3 &p_center_of_mass) { } void JoltBody3D::set_max_contacts_reported(int p_count) { - ERR_FAIL_COND(p_count < 0); + ERR_FAIL_INDEX(p_count, MAX_CONTACTS_REPORTED_3D_MAX); if (unlikely((int)contacts.size() == p_count)) { return; diff --git a/scene/2d/physics/rigid_body_2d.cpp b/scene/2d/physics/rigid_body_2d.cpp index 5416d9082ab..0992d0c2176 100644 --- a/scene/2d/physics/rigid_body_2d.cpp +++ b/scene/2d/physics/rigid_body_2d.cpp @@ -498,6 +498,7 @@ bool RigidBody2D::is_sleeping() const { } void RigidBody2D::set_max_contacts_reported(int p_amount) { + ERR_FAIL_INDEX_MSG(p_amount, MAX_CONTACTS_REPORTED_2D_MAX, "Max contacts reported allocates memory (about 100 bytes each), and therefore must not be set too high."); max_contacts_reported = p_amount; PhysicsServer2D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } diff --git a/scene/3d/physics/rigid_body_3d.cpp b/scene/3d/physics/rigid_body_3d.cpp index 6cf261ced7b..b96c4f050cb 100644 --- a/scene/3d/physics/rigid_body_3d.cpp +++ b/scene/3d/physics/rigid_body_3d.cpp @@ -521,6 +521,7 @@ bool RigidBody3D::is_sleeping() const { } void RigidBody3D::set_max_contacts_reported(int p_amount) { + ERR_FAIL_INDEX_MSG(p_amount, MAX_CONTACTS_REPORTED_3D_MAX, "Max contacts reported allocates memory (about 80 bytes each), and therefore must not be set too high."); max_contacts_reported = p_amount; PhysicsServer3D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index dcbdc922da6..9c5bb233e3b 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -34,6 +34,8 @@ #include "core/object/class_db.h" #include "core/object/ref_counted.h" +constexpr int MAX_CONTACTS_REPORTED_2D_MAX = 4096; + class PhysicsDirectSpaceState2D; template class TypedArray; diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index 979c66fb687..921b590ce61 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -35,6 +35,8 @@ #include "core/io/resource.h" #include "core/object/gdvirtual.gen.inc" +constexpr int MAX_CONTACTS_REPORTED_3D_MAX = 4096; + class PhysicsDirectSpaceState3D; template class TypedArray;