Merge pull request #101011 from aaronfranke/limit-max-contacts-reported

Place a hard limit on the `max_contacts_reported` property in 2D/3D physics
This commit is contained in:
Thaddeus Crews 2025-04-09 18:11:53 -05:00
commit 171187d1aa
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
7 changed files with 9 additions and 1 deletions

View file

@ -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) {

View file

@ -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) {

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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 <typename T>
class TypedArray;

View file

@ -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 <typename T>
class TypedArray;