From 6322facb53c19b9eb8603bf7556bfe12033e3fc1 Mon Sep 17 00:00:00 2001 From: Chris Sinclair Date: Tue, 23 Feb 2021 17:11:18 +0000 Subject: [PATCH] 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. --- src/models.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models.c b/src/models.c index 695935cea..0ee2804ee 100644 --- a/src/models.c +++ b/src/models.c @@ -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); }