Merge pull request #34594 from marstaik/gltf_colorfix_u

Fix Hard Crash on glTF Color Accessor Import
This commit is contained in:
Rémi Verschelde 2019-12-30 16:35:02 +01:00 committed by GitHub
commit e799271bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -855,25 +855,24 @@ PoolVector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &
const int type = state.accessors[p_accessor].type; const int type = state.accessors[p_accessor].type;
ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret); ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret);
int components; int vec_len = 3;
if (type == TYPE_VEC3) { if (type == TYPE_VEC4) {
components = 3; vec_len = 4;
} else { // TYPE_VEC4
components = 4;
} }
ERR_FAIL_COND_V(attribs.size() % components != 0, ret); ERR_FAIL_COND_V(attribs.size() % vec_len != 0, ret);
const double *attribs_ptr = attribs.ptr(); const double *attribs_ptr = attribs.ptr();
const int ret_size = attribs.size() / components; const int ret_size = attribs.size() / vec_len;
ret.resize(ret_size); ret.resize(ret_size);
{ {
PoolVector<Color>::Write w = ret.write(); PoolVector<Color>::Write w = ret.write();
for (int i = 0; i < ret_size; i++) { for (int i = 0; i < ret_size; i++) {
w[i] = Color(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], components == 4 ? attribs_ptr[i * 4 + 3] : 1.0); w[i] = Color(attribs_ptr[i * vec_len + 0], attribs_ptr[i * vec_len + 1], attribs_ptr[i * vec_len + 2], vec_len == 4 ? attribs_ptr[i * 4 + 3] : 1.0);
} }
} }
return ret; return ret;
} }
Vector<Quat> EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { Vector<Quat> EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);