MeshDataTool::create_from_surface Fail on invalid index data
(cherry picked from commit 8e82cf8174
)
This commit is contained in:
parent
82b31fe8e7
commit
80e4b2d02e
1 changed files with 22 additions and 16 deletions
|
@ -52,6 +52,28 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf
|
|||
int vcount = varray.size();
|
||||
ERR_FAIL_COND_V(vcount == 0, ERR_INVALID_PARAMETER);
|
||||
|
||||
PoolVector<int> indices;
|
||||
|
||||
if (arrays[Mesh::ARRAY_INDEX].get_type() != Variant::NIL) {
|
||||
|
||||
indices = arrays[Mesh::ARRAY_INDEX];
|
||||
} else {
|
||||
//make code simpler
|
||||
indices.resize(vcount);
|
||||
PoolVector<int>::Write iw = indices.write();
|
||||
for (int i = 0; i < vcount; i++)
|
||||
iw[i] = i;
|
||||
}
|
||||
|
||||
int icount = indices.size();
|
||||
PoolVector<int>::Read r = indices.read();
|
||||
|
||||
ERR_FAIL_COND_V(icount == 0, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(icount % 3, ERR_INVALID_PARAMETER);
|
||||
for (int i = 0; i < icount; i++) {
|
||||
ERR_FAIL_INDEX_V(r[i], vcount, ERR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
clear();
|
||||
format = p_mesh->surface_get_format(p_surface);
|
||||
material = p_mesh->surface_get_material(p_surface);
|
||||
|
@ -121,22 +143,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf
|
|||
vertices.write[i] = v;
|
||||
}
|
||||
|
||||
PoolVector<int> indices;
|
||||
|
||||
if (arrays[Mesh::ARRAY_INDEX].get_type() != Variant::NIL) {
|
||||
|
||||
indices = arrays[Mesh::ARRAY_INDEX];
|
||||
} else {
|
||||
//make code simpler
|
||||
indices.resize(vcount);
|
||||
PoolVector<int>::Write iw = indices.write();
|
||||
for (int i = 0; i < vcount; i++)
|
||||
iw[i] = i;
|
||||
}
|
||||
|
||||
int icount = indices.size();
|
||||
PoolVector<int>::Read r = indices.read();
|
||||
|
||||
Map<Point2i, int> edge_indices;
|
||||
|
||||
for (int i = 0; i < icount; i += 3) {
|
||||
|
|
Loading…
Reference in a new issue