Fix SoftDynamicBody3D crash when setting disable mode
Proper logic for changing physics state when disabled and disabled mode is changed (it was unnecessarily making calls to re-initialize physics). Extra error handling in soft body implementations to avoid crashes with invalid mesh.
This commit is contained in:
parent
fad7034e8b
commit
e6f7235ffb
3 changed files with 3 additions and 7 deletions
|
@ -116,6 +116,7 @@ void SoftBodyBullet::set_soft_mesh(RID p_mesh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Array arrays = RenderingServer::get_singleton()->mesh_surface_get_arrays(soft_mesh, 0);
|
Array arrays = RenderingServer::get_singleton()->mesh_surface_get_arrays(soft_mesh, 0);
|
||||||
|
ERR_FAIL_COND(arrays.is_empty());
|
||||||
|
|
||||||
bool success = set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]);
|
bool success = set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
|
@ -552,15 +552,9 @@ void SoftDynamicBody3D::set_disable_mode(DisableMode p_mode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool inside_tree = is_inside_tree();
|
|
||||||
|
|
||||||
if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) {
|
|
||||||
_prepare_physics_server();
|
|
||||||
}
|
|
||||||
|
|
||||||
disable_mode = p_mode;
|
disable_mode = p_mode;
|
||||||
|
|
||||||
if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) {
|
if (mesh.is_valid() && is_inside_tree() && !is_enabled()) {
|
||||||
_prepare_physics_server();
|
_prepare_physics_server();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,7 @@ void GodotSoftBody3D::set_mesh(RID p_mesh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Array arrays = RenderingServer::get_singleton()->mesh_surface_get_arrays(soft_mesh, 0);
|
Array arrays = RenderingServer::get_singleton()->mesh_surface_get_arrays(soft_mesh, 0);
|
||||||
|
ERR_FAIL_COND(arrays.is_empty());
|
||||||
|
|
||||||
bool success = create_from_trimesh(arrays[RenderingServer::ARRAY_INDEX], arrays[RenderingServer::ARRAY_VERTEX]);
|
bool success = create_from_trimesh(arrays[RenderingServer::ARRAY_INDEX], arrays[RenderingServer::ARRAY_VERTEX]);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
Loading…
Reference in a new issue