Fix #19245: NPE in UpdateRideApproachExitWaypoints() (#19252)

* Fix #19245: NPE in UpdateRideApproachExitWaypoints()

* Apply suggestions from code review

Co-authored-by: Tulio Leao <tupaschoal@gmail.com>
This commit is contained in:
Michael Steenbeek 2023-01-25 21:48:37 +01:00 committed by GitHub
parent 1bf5d2eb50
commit c260a95abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 7 deletions

View File

@ -4515,16 +4515,26 @@ void Guest::UpdateRideApproachExitWaypoints()
return;
}
const auto& rtd = ride->GetRideTypeDescriptor();
CoordsXY targetLoc = rtd.GetGuestWaypointLocation(*vehicle, *ride, CurrentRideStation);
RideObjectEntry* rideEntry = vehicle->GetRideEntry();
CarEntry* carEntry = &rideEntry->Cars[vehicle->vehicle_type];
if (rideEntry == nullptr)
return;
Guard::Assert((Var37 & 3) < 3);
targetLoc.x += carEntry->peep_loading_waypoints[Var37 / 4][Var37 & 3].x;
targetLoc.y += carEntry->peep_loading_waypoints[Var37 / 4][Var37 & 3].y;
if (vehicle->vehicle_type >= std::size(rideEntry->Cars))
return;
const CarEntry& carEntry = rideEntry->Cars[vehicle->vehicle_type];
const size_t carPosition = Var37 / 4;
if (carPosition >= carEntry.peep_loading_waypoints.size())
return;
const auto waypoint = Var37 & 3;
Guard::Assert(waypoint < 3);
const auto& rtd = ride->GetRideTypeDescriptor();
CoordsXY targetLoc = rtd.GetGuestWaypointLocation(*vehicle, *ride, CurrentRideStation);
targetLoc += carEntry.peep_loading_waypoints[carPosition][waypoint];
SetDestination(targetLoc);
return;
}