From 112985c5bc2c9a3f58c4ee5c4a674beff8b75e58 Mon Sep 17 00:00:00 2001 From: BimDav <67792882+BimDav@users.noreply.github.com> Date: Mon, 27 Sep 2021 09:38:44 +0200 Subject: [PATCH] Reload kinematic shapes when changing PhysicsBody mode to Kinematic to prevent a crash when calling test_body_motion. Call reload_kinematic_shapes from init_kinematic_utilities as they are always called together. --- modules/bullet/rigid_body_bullet.cpp | 2 +- modules/bullet/space_bullet.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 0d2cd1f5a06..22e7b6fe642 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -303,6 +303,7 @@ RigidBodyBullet::~RigidBodyBullet() { void RigidBodyBullet::init_kinematic_utilities() { kinematic_utilities = memnew(KinematicUtilities(this)); + reload_kinematic_shapes(); } void RigidBodyBullet::destroy_kinematic_utilities() { @@ -534,7 +535,6 @@ void RigidBodyBullet::set_mode(PhysicsServer3D::BodyMode p_mode) { mode = PhysicsServer3D::BODY_MODE_KINEMATIC; reload_axis_lock(); _internal_set_mass(0); - init_kinematic_utilities(); break; case PhysicsServer3D::BODY_MODE_STATIC: mode = PhysicsServer3D::BODY_MODE_STATIC; diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index a9a811c4458..0cfd658bd5f 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -947,7 +947,6 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform3D &p if (!p_body->get_kinematic_utilities()) { p_body->init_kinematic_utilities(); - p_body->reload_kinematic_shapes(); } btVector3 initial_recover_motion(0, 0, 0); @@ -1089,7 +1088,6 @@ int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform3D if (!p_body->get_kinematic_utilities()) { p_body->init_kinematic_utilities(); - p_body->reload_kinematic_shapes(); } btVector3 recover_motion(0, 0, 0);