diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 00c3f0550a..ed29c16be5 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,6 +2,7 @@ ------------------------------------------------------------------------ - Improved: [#26566] Improve the performance of sorting sprites. - Fix: [#26583] The default tab is not highlighted when opening a ride window. +- Fix: [#26602] Crash when locating the nearest mechanic for a ride that has not previously been inspected. 0.5.1 (2026-05-17) ------------------------------------------------------------------------ diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 829e390796..d7e6e37746 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1487,8 +1487,12 @@ static void RideCallClosestMechanic(Ride& ride) Staff* RideFindClosestMechanic(const Ride& ride, int32_t forInspection) { + const auto stationIndex = ride.inspectionStation.IsNull() ? RideGetFirstValidStationExit(ride) : ride.inspectionStation; + if (stationIndex.IsNull()) + return nullptr; + // Get either exit position or entrance position if there is no exit - auto& station = ride.getStation(ride.inspectionStation); + const auto& station = ride.getStation(stationIndex); TileCoordsXYZD location = station.Exit; if (location.IsNull()) {