Skip to content

Commit

Permalink
Remove invalid collision exceptions in PhysicsServerXD::body_get_coll…
Browse files Browse the repository at this point in the history
…ision_exceptions()
  • Loading branch information
Daylily-Zeleen committed Jan 3, 2025
1 parent bdf625b commit fbc7f1d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
15 changes: 13 additions & 2 deletions modules/godot_physics_2d/godot_physics_server_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,19 @@ void GodotPhysicsServer2D::body_get_collision_exceptions(RID p_body, List<RID> *
GodotBody2D *body = body_owner.get_or_null(p_body);
ERR_FAIL_NULL(body);

for (int i = 0; i < body->get_exceptions().size(); i++) {
p_exceptions->push_back(body->get_exceptions()[i]);
const VSet<RID> &exceptions = body->get_exceptions();
LocalVector<RID> invalid_exceptions;
for (int i = 0; i < exceptions.size(); i++) {
RID exception = exceptions[i];
if (body_owner.owns(exception)) {
p_exceptions->push_back(exception);
} else {
invalid_exceptions.push_back(exception);
}
}

for (RID invalid_body : invalid_exceptions) {
body->remove_exception(invalid_body);
}
}

Expand Down
15 changes: 13 additions & 2 deletions modules/godot_physics_3d/godot_physics_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,19 @@ void GodotPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *
GodotBody3D *body = body_owner.get_or_null(p_body);
ERR_FAIL_NULL(body);

for (int i = 0; i < body->get_exceptions().size(); i++) {
p_exceptions->push_back(body->get_exceptions()[i]);
const VSet<RID> &exceptions = body->get_exceptions();
LocalVector<RID> invalid_exceptions;
for (int i = 0; i < exceptions.size(); i++) {
RID exception = exceptions[i];
if (body_owner.owns(exception)) {
p_exceptions->push_back(exception);
} else {
invalid_exceptions.push_back(exception);
}
}

for (RID invalid_body : invalid_exceptions) {
body->remove_exception(invalid_body);
}
}

Expand Down
17 changes: 14 additions & 3 deletions modules/jolt_physics/jolt_physics_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,22 @@ void JoltPhysicsServer3D::body_remove_collision_exception(RID p_body, RID p_exce
}

void JoltPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
const JoltBody3D *body = body_owner.get_or_null(p_body);
JoltBody3D *body = body_owner.get_or_null(p_body);
ERR_FAIL_NULL(body);

for (const RID &exception : body->get_collision_exceptions()) {
p_exceptions->push_back(exception);
const LocalVector<RID> &exceptions = body->get_collision_exceptions();
LocalVector<RID> invalid_exceptions;
for (uint32_t i = 0; i < exceptions.size(); i++) {
RID exception = exceptions[i];
if (body_owner.owns(exception)) {
p_exceptions->push_back(exception);
} else {
invalid_exceptions.push_back(exception);
}
}

for (RID invalid_body : invalid_exceptions) {
body->remove_collision_exception(invalid_body);
}
}

Expand Down

0 comments on commit fbc7f1d

Please sign in to comment.