浏览代码

Merge pull request #108042 from mihe/jolt/soft-body-disable-crash

Fix crash when disabling `SoftBody3D` while using Jolt Physics
Thaddeus Crews 2 月之前
父节点
当前提交
c9f6e21384
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      modules/jolt_physics/objects/jolt_soft_body_3d.cpp

+ 2 - 1
modules/jolt_physics/objects/jolt_soft_body_3d.cpp

@@ -74,7 +74,8 @@ JPH::ObjectLayer JoltSoftBody3D::_get_object_layer() const {
 void JoltSoftBody3D::_space_changing() {
 void JoltSoftBody3D::_space_changing() {
 	JoltObject3D::_space_changing();
 	JoltObject3D::_space_changing();
 
 
-	if (in_space()) {
+	// Note that we should not use `in_space()` as the condition here, since we could have cleared the mesh at this point.
+	if (jolt_body != nullptr) {
 		jolt_settings = new JPH::SoftBodyCreationSettings(jolt_body->GetSoftBodyCreationSettings());
 		jolt_settings = new JPH::SoftBodyCreationSettings(jolt_body->GetSoftBodyCreationSettings());
 		jolt_settings->mSettings = nullptr;
 		jolt_settings->mSettings = nullptr;
 	}
 	}