1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 12:03:07 +01:00

Merge pull request #16628 from Gymnasiast/fix/16572

Fix #16572: Crash Placing Track Designs Due to OOB Read on Research.cpp:554
This commit is contained in:
Michael Steenbeek
2022-02-12 12:29:52 +01:00
committed by GitHub
3 changed files with 14 additions and 8 deletions

View File

@@ -137,10 +137,10 @@ GameActions::Result TrackDesignAction::Execute() const
auto& objManager = OpenRCT2::GetContext()->GetObjectManager();
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.vehicle_object);
if (entryIndex == OBJECT_ENTRY_INDEX_NULL)
if (entryIndex != OBJECT_ENTRY_INDEX_NULL)
{
// Force a fallback if the entry is not invented yet a td6 of it is selected,
// which can happen in select-by-track-type mode
// Force a fallback if the entry is not invented yet a track design using it is selected.
// This can happen on rides with multiple vehicles where some have been invented and some havent.
if (!ride_entry_is_invented(entryIndex) && !gCheatsIgnoreResearchStatus)
{
entryIndex = OBJECT_ENTRY_INDEX_NULL;

View File

@@ -549,8 +549,11 @@ bool ride_type_is_invented(uint32_t rideType)
return RideTypeIsValid(rideType) ? _researchedRideTypes[rideType] : false;
}
bool ride_entry_is_invented(int32_t rideEntryIndex)
bool ride_entry_is_invented(ObjectEntryIndex rideEntryIndex)
{
if (rideEntryIndex >= std::size(_researchedRideEntries))
return false;
return _researchedRideEntries[rideEntryIndex];
}
@@ -562,9 +565,12 @@ void ride_type_set_invented(uint32_t rideType)
}
}
void ride_entry_set_invented(int32_t rideEntryIndex)
void ride_entry_set_invented(ObjectEntryIndex rideEntryIndex)
{
_researchedRideEntries[rideEntryIndex] = true;
if (rideEntryIndex >= std::size(_researchedRideEntries))
log_error("Tried setting ride entry %u as invented", rideEntryIndex);
else
_researchedRideEntries[rideEntryIndex] = true;
}
bool scenery_is_invented(const ScenerySelection& sceneryItem)

View File

@@ -138,11 +138,11 @@ void research_insert_ride_entry(ObjectEntryIndex entryIndex, bool researched);
bool research_insert_scenery_group_entry(ObjectEntryIndex entryIndex, bool researched);
void ride_type_set_invented(uint32_t rideType);
void ride_entry_set_invented(int32_t rideEntryIndex);
void ride_entry_set_invented(ObjectEntryIndex rideEntryIndex);
void scenery_set_invented(const ScenerySelection& sceneryItem);
void scenery_set_not_invented(const ScenerySelection& sceneryItem);
bool ride_type_is_invented(uint32_t rideType);
bool ride_entry_is_invented(int32_t rideEntryIndex);
bool ride_entry_is_invented(ObjectEntryIndex rideEntryIndex);
bool scenery_group_is_invented(int32_t sgIndex);
void scenery_group_set_invented(int32_t sgIndex);
bool scenery_is_invented(const ScenerySelection& sceneryItem);