summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-23 12:28:17 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-23 12:28:17 +0200
commitb9b793237c0b45132c26a8c4bdf6ff1f1266b88c (patch)
tree9638c65c77e10daa3fdd348656b8d3732663bfa5
parent9c9e704a2b6d932734f942fbbfd23138adb2de50 (diff)
parent6764338e096f5ca72fa4f7750f85d8ed5d9d5a65 (diff)
downloadredot-engine-b9b793237c0b45132c26a8c4bdf6ff1f1266b88c.tar.gz
Merge pull request #97315 from lawnjelly/fix_character_platform
Fix physics platform behaviour regression
-rw-r--r--scene/3d/physics/character_body_3d.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/scene/3d/physics/character_body_3d.cpp b/scene/3d/physics/character_body_3d.cpp
index dda3ea9cca..e3815e8219 100644
--- a/scene/3d/physics/character_body_3d.cpp
+++ b/scene/3d/physics/character_body_3d.cpp
@@ -60,8 +60,13 @@ bool CharacterBody3D::move_and_slide() {
// We need to check the platform_rid object still exists before accessing.
// A valid RID is no guarantee that the object has not been deleted.
- if (ObjectDB::get_instance(platform_object_id)) {
- //this approach makes sure there is less delay between the actual body velocity and the one we saved
+
+ // We can only perform the ObjectDB lifetime check on Object derived objects.
+ // Note that physics also creates RIDs for non-Object derived objects, these cannot
+ // be lifetime checked through ObjectDB, and therefore there is a still a vulnerability
+ // to dangling RIDs (access after free) in this scenario.
+ if (platform_object_id.is_null() || ObjectDB::get_instance(platform_object_id)) {
+ // This approach makes sure there is less delay between the actual body velocity and the one we saved.
bs = PhysicsServer3D::get_singleton()->body_get_direct_state(platform_rid);
}