1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Place a hard limit on the max_contacts_reported property

This commit is contained in:
Aaron Franke
2025-01-01 17:20:07 -08:00
parent 7598b08ec2
commit a5de242a2f
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;