Fix segfault for glTF animations not keyframed at 0

When loading glTF animations we lerp between keyframes, and previously
assume that if the frame we are considering has a later keyframe, there
must be a previous keyframe. This is not true if the animation's first
keyframe is some time into the animation. In this case we now
effectively clamp to that first keyframe for any time prior to it.
This commit is contained in:
Chris Sinclair 2021-02-23 17:11:18 +00:00
parent 6c67ef3da0
commit 6322facb53
No known key found for this signature in database
GPG Key ID: 5C323201E3EF4E75

View File

@ -4120,11 +4120,11 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
if (frameTime < inputFrameTime)
{
shouldSkipFurtherTransformation = false;
outputMin = j - 1;
outputMin = (j == 0) ? 0 : j - 1;
outputMax = j;
float previousInputTime = 0.0f;
if (GltfReadFloat(sampler->input, j - 1, (float*)&previousInputTime, 1))
if (GltfReadFloat(sampler->input, outputMin, (float*)&previousInputTime, 1))
{
lerpPercent = (frameTime - previousInputTime) / (inputFrameTime - previousInputTime);
}