fix scrolling texture interp integer overflow (#72)
This commit is contained in:
parent
b959ba90d9
commit
570afe946e
|
@ -154,13 +154,13 @@ void uv_update_scroll(void) {
|
|||
// Prepare for interpolation
|
||||
if (bhv < SCROLL_UV_X) {
|
||||
u8 bhvIndex = MIN(bhv, 2);
|
||||
for (u16 k = 0; k < scroll->size; k++) {
|
||||
scroll->prevF32[k] = verts[k]->n.ob[bhvIndex];
|
||||
for (u16 i = 0; i < scroll->size; i++) {
|
||||
scroll->prevF32[i] = verts[i]->n.ob[bhvIndex];
|
||||
}
|
||||
} else {
|
||||
u8 bhvIndex = MIN(bhv-SCROLL_UV_X, 1);
|
||||
for (u16 k = 0; k < scroll->size; k++) {
|
||||
scroll->prevS16[k] = verts[k]->n.tc[bhvIndex];
|
||||
for (u16 i = 0; i < scroll->size; i++) {
|
||||
scroll->prevS16[i] = verts[i]->n.tc[bhvIndex];
|
||||
}
|
||||
}
|
||||
scroll->needInterp = true;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "scroll_targets.h"
|
||||
#include "pc/lua/utils/smlua_math_utils.h"
|
||||
|
||||
static struct ScrollTarget *sScrollTargets = NULL;
|
||||
|
||||
|
@ -21,6 +22,7 @@ struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset) {
|
|||
|
||||
// If we need to, realloc the block of vertices
|
||||
if ((!scroll->hasOffset && offset > 0) || size < scroll->size) {
|
||||
if (scroll->hasOffset) { return NULL; }
|
||||
if (size > scroll->size) { size = scroll->size; } // Don't use an invalid size
|
||||
scroll->hasOffset = true;
|
||||
Vtx* *newVtx = calloc(size, sizeof(Vtx*));
|
||||
|
@ -137,6 +139,8 @@ void patch_scroll_targets_before(void) {
|
|||
}
|
||||
}
|
||||
|
||||
#define SHORT_RANGE 32767
|
||||
|
||||
void patch_scroll_targets_interpolated(f32 delta) {
|
||||
f32 antiDelta = 1.0f - delta;
|
||||
struct ScrollTarget *scroll = sScrollTargets;
|
||||
|
@ -152,7 +156,7 @@ void patch_scroll_targets_interpolated(f32 delta) {
|
|||
} else {
|
||||
u8 bhvIndex = MIN(scroll->bhv-SCROLL_UV_X, 1);
|
||||
for (u16 k = 0; k < scroll->size; k++) {
|
||||
verts[k]->n.tc[bhvIndex] = (int) scroll->prevS16[k] * antiDelta + scroll->interpS16[k] * delta;
|
||||
verts[k]->n.tc[bhvIndex] = clampf(scroll->prevS16[k] * antiDelta + scroll->interpS16[k] * delta, -SHORT_RANGE, SHORT_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue