Browse Source

fix for snap to floor editor crash bug

fix for issue #44231: snap_selected_nodes_to_floor() results in an editor
crash when a child collisionshape has invalid shape object

(cherry picked from commit 52f6e0b5ada0baaa91f00cdb045a32872d969ac1)
jeffuntildeath 4 years ago
parent
commit
de7b5006cc
1 changed files with 17 additions and 5 deletions
  1. 17 5
      editor/plugins/spatial_editor_plugin.cpp

+ 17 - 5
editor/plugins/spatial_editor_plugin.cpp

@@ -5803,13 +5803,25 @@ void SpatialEditor::snap_selected_nodes_to_floor() {
 			Set<CollisionShape *> cs = _get_child_nodes<CollisionShape>(sp);
 
 			if (cs.size()) {
-				AABB aabb = sp->get_global_transform().xform(cs.front()->get()->get_shape()->get_debug_mesh()->get_aabb());
+				AABB aabb;
+				bool found_valid_shape = false;
+				if (cs.front()->get()->get_shape().is_valid()) {
+					aabb = sp->get_global_transform().xform(cs.front()->get()->get_shape()->get_debug_mesh()->get_aabb());
+					found_valid_shape = true;
+				}
 				for (Set<CollisionShape *>::Element *I = cs.front(); I; I = I->next()) {
-					aabb.merge_with(sp->get_global_transform().xform(I->get()->get_shape()->get_debug_mesh()->get_aabb()));
+					if (I->get()->get_shape().is_valid()) {
+						aabb.merge_with(sp->get_global_transform().xform(I->get()->get_shape()->get_debug_mesh()->get_aabb()));
+						found_valid_shape = true;
+					}
+				}
+				if (found_valid_shape) {
+					Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5);
+					from = aabb.position + size;
+					position_offset.y = from.y - sp->get_global_transform().origin.y;
+				} else {
+					from = sp->get_global_transform().origin;
 				}
-				Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5);
-				from = aabb.position + size;
-				position_offset.y = from.y - sp->get_global_transform().origin.y;
 			} else if (vi.size()) {
 				AABB aabb = vi.front()->get()->get_transformed_aabb();
 				for (Set<VisualInstance *>::Element *I = vi.front(); I; I = I->next()) {