Better fix for crash in cur_obj_follow_path()

This commit is contained in:
MysterD 2022-03-05 14:38:17 -08:00
parent 202bd1964c
commit 369a7cd7e5
1 changed files with 10 additions and 3 deletions

View File

@ -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;