From 64807147e6823a7133eeb0de8f199ceeceb346ed Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Sat, 6 Mar 2021 20:57:48 +0100 Subject: [PATCH] Fix #14126: assertion in research_fix() The assertion was hit because of a non-existant ride type being passed into ride_type_set_invented(). Try to avoid this by fixing DAT files when loading them. --- src/openrct2/object/RideObject.cpp | 4 +++- src/openrct2/ride/RideData.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 70ad0217a3..7024fd4d86 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -57,6 +57,8 @@ void RideObject::ReadLegacy(IReadObjectContext* context, IStream* stream) for (auto& rideType : _legacyType.ride_type) { rideType = stream->ReadValue(); + if (!RideTypeIsValid(rideType)) + rideType = RIDE_TYPE_NULL; } _legacyType.min_cars_in_train = stream->ReadValue(); _legacyType.max_cars_in_train = stream->ReadValue(); @@ -537,7 +539,7 @@ void RideObject::ReadJson(IReadObjectContext* context, json_t& root) for (size_t i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) { - uint8_t rideType = RIDE_TYPE_NULL; + ObjectEntryIndex rideType = RIDE_TYPE_NULL; if (i < numRideTypes) { diff --git a/src/openrct2/ride/RideData.h b/src/openrct2/ride/RideData.h index 351250ee2c..83a56c06b4 100644 --- a/src/openrct2/ride/RideData.h +++ b/src/openrct2/ride/RideData.h @@ -360,4 +360,9 @@ constexpr const RideTypeDescriptor& GetRideTypeDescriptor(ObjectEntryIndex rideT return RideTypeDescriptors[rideType]; } +constexpr bool RideTypeIsValid(ObjectEntryIndex rideType) +{ + return rideType < std::size(RideTypeDescriptors); +} + #endif