From 2b76ba23ff730e58c622d2013eec49c9ce8aa5f2 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Thu, 19 Mar 2026 21:30:42 +1000 Subject: [PATCH] fix a logic error in scrolling textures --- src/game/behaviors/texscroll.inc.c | 18 ++++++------------ src/game/scroll_targets.c | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/game/behaviors/texscroll.inc.c b/src/game/behaviors/texscroll.inc.c index 10eeed2fa..c2fc62bba 100644 --- a/src/game/behaviors/texscroll.inc.c +++ b/src/game/behaviors/texscroll.inc.c @@ -133,16 +133,16 @@ void uv_update_scroll(void) { scroll->hasInterpInit = true; scroll->bhv = bhv; if (bhv < SCROLL_UV_X) { - scroll->interpF32 = calloc(scroll->size, sizeof(f32)); - scroll->prevF32 = calloc(scroll->size, sizeof(f32)); + scroll->interpF32 = malloc(scroll->size * sizeof(f32)); + scroll->prevF32 = malloc(scroll->size * sizeof(f32)); u8 bhvIndex = MIN(bhv, 2); for (u32 k = 0; k < scroll->size; k++) { scroll->interpF32[k] = verts[k]->n.ob[bhvIndex]; } } else { - scroll->interpS16 = calloc(scroll->size, sizeof(s16)); - scroll->prevS16 = calloc(scroll->size, sizeof(s16)); + scroll->interpS16 = malloc(scroll->size * sizeof(s16)); + scroll->prevS16 = malloc(scroll->size * sizeof(s16)); u8 bhvIndex = MIN(bhv-SCROLL_UV_X, 1); for (u32 k = 0; k < scroll->size; k++) { @@ -153,15 +153,9 @@ void uv_update_scroll(void) { // Prepare for interpolation if (bhv < SCROLL_UV_X) { - u8 bhvIndex = MIN(bhv, 2); - for (u32 i = 0; i < scroll->size; i++) { - scroll->prevF32[i] = verts[i]->n.ob[bhvIndex]; - } + memcpy(scroll->prevF32, scroll->interpF32, scroll->size * sizeof(f32)); } else { - u8 bhvIndex = MIN(bhv-SCROLL_UV_X, 1); - for (u32 i = 0; i < scroll->size; i++) { - scroll->prevS16[i] = verts[i]->n.tc[bhvIndex]; - } + memcpy(scroll->prevS16, scroll->interpS16, scroll->size * sizeof(s16)); } scroll->needInterp = true; diff --git a/src/game/scroll_targets.c b/src/game/scroll_targets.c index 20d7df51a..13d06cefc 100644 --- a/src/game/scroll_targets.c +++ b/src/game/scroll_targets.c @@ -18,7 +18,7 @@ struct ScrollTarget *get_scroll_targets(u32 id, u16 size, u16 offset) { if (size > scroll->size) { size = scroll->size; } // Don't use an invalid size if (size + offset >= scroll->size) { return NULL; } // If the offset is invalid, Abort. scroll->hasOffset = true; - Vtx* *newVtx = calloc(size, sizeof(Vtx*)); + Vtx* *newVtx = malloc(size * sizeof(Vtx*)); if (!newVtx) { return NULL; } for (u32 i = 0; i < size; i++) { newVtx[i] = scroll->vertices[i + offset]; @@ -51,11 +51,18 @@ struct ScrollTarget* find_or_create_scroll_targets(u32 id, bool hasOffset) { } if (scroll == NULL) { - scroll = calloc(1, sizeof(struct ScrollTarget)); + scroll = malloc(sizeof(struct ScrollTarget)); scroll->id = id; scroll->size = 0; scroll->vertices = NULL; scroll->hasOffset = hasOffset; + scroll->hasInterpInit = false; + scroll->needInterp = false; + scroll->interpF32 = NULL; + scroll->prevF32 = NULL; + scroll->interpS16 = NULL; + scroll->prevS16 = NULL; + scroll->bhv = 0; hmap_put(sScrollTargets, id, scroll); } @@ -77,8 +84,10 @@ void add_vtx_scroll_target(u32 id, Vtx *vtx, u32 size, bool hasOffset) { Vtx* *newArray = realloc(scroll->vertices, newSize); if (!newArray) { - newArray = calloc(1, newSize); + newArray = malloc(newSize); + if (!newArray) { return; } memcpy(newArray, scroll->vertices, oldSize); + memset(newArray + scroll->size, 0, size * sizeof(Vtx*)); free(scroll->vertices); }