Check array sizes before trying to remove items from arrays in merge_mesh_array.

This commit is contained in:
Relintai 2021-12-30 00:00:25 +01:00
parent ca1f54268b
commit de821908e9

View File

@ -67,23 +67,35 @@ Array MeshUtils::merge_mesh_array(Array arr) const {
int remk = rem - k; int remk = rem - k;
verts.remove(remk); verts.remove(remk);
normals.remove(remk); if (normals.size() > 0)
uvs.remove(remk); normals.remove(remk);
colors.remove(remk); if (uvs.size() > 0)
uvs.remove(remk);
if (colors.size() > 0)
colors.remove(remk);
int bindex = remk * 4; if (bones.size() > 0) {
for (int l = 0; l < 4; ++l) { int bindex = remk * 4;
bones.remove(bindex); for (int l = 0; l < 4; ++l) {
weights.remove(bindex); bones.remove(bindex);
}
}
if (weights.size() > 0) {
int bindex = remk * 4;
for (int l = 0; l < 4; ++l) {
weights.remove(bindex);
}
} }
for (int j = 0; j < indices.size(); ++j) { for (int j = 0; j < indices.size(); ++j) {
int indx = indices[j]; int indx = indices[j];
if (indx == remk) if (indx == remk) {
indices.set(j, i); indices.set(j, i);
else if (indx > remk) } else if (indx > remk) {
indices.set(j, indx - 1); indices.set(j, indx - 1);
}
} }
} }
@ -98,12 +110,12 @@ Array MeshUtils::merge_mesh_array(Array arr) const {
arr[VisualServer::ARRAY_TEX_UV] = uvs; arr[VisualServer::ARRAY_TEX_UV] = uvs;
if (colors.size() > 0) if (colors.size() > 0)
arr[VisualServer::ARRAY_COLOR] = colors; arr[VisualServer::ARRAY_COLOR] = colors;
if (indices.size() > 0)
arr[VisualServer::ARRAY_INDEX] = indices;
if (bones.size() > 0) if (bones.size() > 0)
arr[VisualServer::ARRAY_BONES] = bones; arr[VisualServer::ARRAY_BONES] = bones;
if (weights.size() > 0) if (weights.size() > 0)
arr[VisualServer::ARRAY_WEIGHTS] = weights; arr[VisualServer::ARRAY_WEIGHTS] = weights;
if (indices.size() > 0)
arr[VisualServer::ARRAY_INDEX] = indices;
return arr; return arr;
} }