Browse Source

Prevent MeshDataTool from crashing due to invalid bones/weights arrays

(cherry picked from commit ec15227be81c2bd7e08103e7c46cea8cb5d44f49)
Yuri Sizov 3 years ago
parent
commit
8b94ba1db1
1 changed files with 2 additions and 0 deletions
  1. 2 0
      scene/resources/mesh_data_tool.cpp

+ 2 - 0
scene/resources/mesh_data_tool.cpp

@@ -420,6 +420,7 @@ Vector<int> MeshDataTool::get_vertex_bones(int p_idx) const {
 void MeshDataTool::set_vertex_bones(int p_idx, const Vector<int> &p_bones) {
 void MeshDataTool::set_vertex_bones(int p_idx, const Vector<int> &p_bones) {
 
 
 	ERR_FAIL_INDEX(p_idx, vertices.size());
 	ERR_FAIL_INDEX(p_idx, vertices.size());
+	ERR_FAIL_COND(p_bones.size() != 4);
 	vertices.write[p_idx].bones = p_bones;
 	vertices.write[p_idx].bones = p_bones;
 	format |= Mesh::ARRAY_FORMAT_BONES;
 	format |= Mesh::ARRAY_FORMAT_BONES;
 }
 }
@@ -431,6 +432,7 @@ Vector<float> MeshDataTool::get_vertex_weights(int p_idx) const {
 }
 }
 void MeshDataTool::set_vertex_weights(int p_idx, const Vector<float> &p_weights) {
 void MeshDataTool::set_vertex_weights(int p_idx, const Vector<float> &p_weights) {
 	ERR_FAIL_INDEX(p_idx, vertices.size());
 	ERR_FAIL_INDEX(p_idx, vertices.size());
+	ERR_FAIL_COND(p_weights.size() != 4);
 	vertices.write[p_idx].weights = p_weights;
 	vertices.write[p_idx].weights = p_weights;
 	format |= Mesh::ARRAY_FORMAT_WEIGHTS;
 	format |= Mesh::ARRAY_FORMAT_WEIGHTS;
 }
 }