From c5a4c465198c3af4617dc4484d23b6c7da07f0e8 Mon Sep 17 00:00:00 2001 From: MysterD Date: Wed, 8 Nov 2023 13:12:33 -0800 Subject: [PATCH] Fix crash in move_into_c_up() --- src/game/camera.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/game/camera.c b/src/game/camera.c index 5321e1f2..73df3b1a 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -2750,20 +2750,21 @@ void move_into_c_up(struct Camera *c) { if (!c) { return; } struct LinearTransitionPoint *start = &sModeInfo.transitionStart; struct LinearTransitionPoint *end = &sModeInfo.transitionEnd; + s16 modInfoMax = MAX(sModeInfo.frame, 1); f32 dist = end->dist - start->dist; s16 pitch = end->pitch - start->pitch; s16 yaw = end->yaw - start->yaw; // Linearly interpolate from start to end position's polar coordinates - dist = start->dist + dist * sModeInfo.frame / sModeInfo.max; - pitch = start->pitch + pitch * sModeInfo.frame / sModeInfo.max; - yaw = start->yaw + yaw * sModeInfo.frame / sModeInfo.max; + dist = start->dist + dist * sModeInfo.frame / modInfoMax; + pitch = start->pitch + pitch * sModeInfo.frame / modInfoMax; + yaw = start->yaw + yaw * sModeInfo.frame / modInfoMax; // Linearly interpolate the focus from start to end - c->focus[0] = start->focus[0] + (end->focus[0] - start->focus[0]) * sModeInfo.frame / sModeInfo.max; - c->focus[1] = start->focus[1] + (end->focus[1] - start->focus[1]) * sModeInfo.frame / sModeInfo.max; - c->focus[2] = start->focus[2] + (end->focus[2] - start->focus[2]) * sModeInfo.frame / sModeInfo.max; + c->focus[0] = start->focus[0] + (end->focus[0] - start->focus[0]) * sModeInfo.frame / modInfoMax; + c->focus[1] = start->focus[1] + (end->focus[1] - start->focus[1]) * sModeInfo.frame / modInfoMax; + c->focus[2] = start->focus[2] + (end->focus[2] - start->focus[2]) * sModeInfo.frame / modInfoMax; vec3f_add(c->focus, sMarioCamState->pos); vec3f_set_dist_and_angle(c->focus, c->pos, dist, pitch, yaw); @@ -2772,7 +2773,7 @@ void move_into_c_up(struct Camera *c) { sMarioCamState->headRotation[1] = 0; // Finished zooming in - if (++sModeInfo.frame == sModeInfo.max) { + if (++sModeInfo.frame >= modInfoMax) { gCameraMovementFlags &= ~CAM_MOVING_INTO_MODE; } } @@ -2965,7 +2966,7 @@ void set_camera_mode(struct Camera *c, s16 mode, s16 frames) { sModeInfo.newMode = (mode != -1) ? mode : sModeInfo.lastMode; sModeInfo.lastMode = c->mode; - sModeInfo.max = frames; + sModeInfo.max = MAX(frames, 1); sModeInfo.frame = 1; c->mode = sModeInfo.newMode;