Skip to content

Commit

Permalink
model: Don't die on single frame animations
Browse files Browse the repository at this point in the history
Currently, the animation channel transformation code assumes that there
are at least 2 points in a channel and the arithmetic causes an out of
memory access if there's only one.

Add a bit of a special case for single frame animations.

Signed-off-by: Alexander Shishkin <[email protected]>
  • Loading branch information
virtuoso committed Oct 7, 2024
1 parent f4d286f commit 08b424c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ static void channel_time_to_idx(struct channel *chan, float time, int start, int
goto tail;

*prev = max(i - 1, 0);
*next = *prev + 1;
*next = min(*prev + 1, chan->nr - 1);
return;

tail:
Expand Down Expand Up @@ -1198,7 +1198,7 @@ static void channel_transform(struct entity3d *e, struct channel *chan, float ti
struct model3d *model = e->txmodel->model;
void *p_data, *n_data;
struct joint *joint = &e->joints[chan->target];
float p_time, n_time, fac;
float p_time, n_time, fac = 0;
int prev, next;
mat4x4 rot;

Expand All @@ -1209,7 +1209,7 @@ static void channel_transform(struct entity3d *e, struct channel *chan, float ti
n_time = chan->time[next];
if (p_time > n_time)
fac = time < n_time ? 1 : 0;
else
else if (p_time < n_time)
fac = (time - p_time) / (n_time - p_time);

p_data = (void *)chan->data + prev * chan->stride;
Expand Down

0 comments on commit 08b424c

Please sign in to comment.