From 369a7cd7e56a8c216dd3700d0709dae5f794b84e Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 5 Mar 2022 14:38:17 -0800 Subject: [PATCH] Better fix for crash in cur_obj_follow_path() --- src/game/object_helpers.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index c5874df2..abe9fa9e 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -2138,8 +2138,13 @@ s32 cur_obj_follow_path(UNUSED s32 unusedArg) { startWaypoint = o->oPathedStartWaypoint; lastWaypoint = o->oPathedPrevWaypoint; - if ((lastWaypoint + 1)->flags != WAYPOINT_FLAGS_END) { - targetWaypoint = lastWaypoint + 1; + // sanity check waypoints + if (lastWaypoint == NULL) { lastWaypoint = startWaypoint; } + struct Waypoint* tmpWaypoint = (lastWaypoint + 1); + if (tmpWaypoint == NULL) { tmpWaypoint = lastWaypoint; } + + if (tmpWaypoint->flags != WAYPOINT_FLAGS_END) { + targetWaypoint = tmpWaypoint; } else { targetWaypoint = startWaypoint; } @@ -2161,7 +2166,9 @@ s32 cur_obj_follow_path(UNUSED s32 unusedArg) { // If dot(prevToNext, objToNext) <= 0 (i.e. reached other side of target waypoint) if (prevToNextX * objToNextX + prevToNextY * objToNextY + prevToNextZ * objToNextZ <= 0.0f) { o->oPathedPrevWaypoint = targetWaypoint; - if ((targetWaypoint + 1)->flags == WAYPOINT_FLAGS_END) { + struct Waypoint* tmpWaypoint2 = (targetWaypoint + 1); + if (tmpWaypoint2 == NULL) { tmpWaypoint2 = targetWaypoint; } + if (tmpWaypoint2->flags == WAYPOINT_FLAGS_END) { return PATH_REACHED_END; } else { return PATH_REACHED_WAYPOINT;