Skip to content

Commit

Permalink
Place a hard limit on the max_contacts_reported property
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Jan 2, 2025
1 parent 2582793 commit c6ceef1
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/godot_physics_2d/godot_body_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class GodotBody2D : public GodotCollisionObject2D {
}

_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) {
Expand Down
1 change: 1 addition & 0 deletions modules/godot_physics_3d/godot_body_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class GodotBody3D : public GodotCollisionObject3D {
}

_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) {
Expand Down
2 changes: 1 addition & 1 deletion modules/jolt_physics/objects/jolt_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,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;
Expand Down
1 change: 1 addition & 0 deletions scene/2d/physics/rigid_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions scene/3d/physics/rigid_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions servers/physics_server_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "core/object/class_db.h"
#include "core/object/ref_counted.h"

constexpr int MAX_CONTACTS_REPORTED_2D_MAX = 100'000'000;

class PhysicsDirectSpaceState2D;
template <typename T>
class TypedArray;
Expand Down
2 changes: 2 additions & 0 deletions servers/physics_server_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"

constexpr int MAX_CONTACTS_REPORTED_3D_MAX = 100'000'000;

class PhysicsDirectSpaceState3D;
template <typename T>
class TypedArray;
Expand Down

0 comments on commit c6ceef1

Please sign in to comment.