Merge pull request #15485 from sabrina-shanman/crash_hfm_normals

(case 22026) Fix crash due to invalid indices in baker::calculateNormals
This commit is contained in:
Shannon Romano 2019-05-13 13:06:01 -07:00 committed by GitHub
commit 12bb073d14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View file

@ -61,7 +61,7 @@ void CalculateBlendshapeNormalsTask::run(const baker::BakeContextPointer& contex
outVertex = blendshape.vertices[lookupIndex];
} else {
// Index isn't in the blendshape, so return vertex from mesh
outVertex = mesh.vertices[lookupIndex];
outVertex = baker::safeGet(mesh.vertices, lookupIndex);
}
});
}

View file

@ -32,7 +32,7 @@ void CalculateMeshNormalsTask::run(const baker::BakeContextPointer& context, con
return &normalsOut[normalIndex];
},
[&mesh](int vertexIndex, glm::vec3& outVertex) /* VertexSetter */ {
outVertex = mesh.vertices[vertexIndex];
outVertex = baker::safeGet(mesh.vertices, vertexIndex);
}
);
}

View file

@ -25,6 +25,17 @@ namespace baker {
}
}
template<typename T>
const T& safeGet(const QVector<T>& data, int i) {
static T t;
if (i >= 0 && data.size() > i) {
return data[i];
} else {
return t;
}
}
// Returns a reference to the normal at the specified index, or nullptr if it cannot be accessed
using NormalAccessor = std::function<glm::vec3*(int index)>;