1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-24 15:24:30 +01:00

Fix: Writing out of bounds when trains have over 144 cars

This commit is contained in:
Hielke Morsink
2022-04-27 22:02:39 +02:00
committed by GitHub
parent 1c55e6ee7a
commit 35915b0a5d
2 changed files with 6 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
0.4.1 (in development)
------------------------------------------------------------------------
- Fix: [#16974] Small scenery ghosts can be deleted.
- Fix: [#17073] Corrupt ride window and random crashes when trains have more than 144 cars.
- Improved: [#17050] Transparency can be enabled directly without needing see-through enabled first.
- Removed: [#16864] Title sequence editor (replaced by plug-in).

View File

@@ -21,6 +21,7 @@
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/Limits.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/GameAction.h>
#include <openrct2/actions/ParkSetParameterAction.h>
@@ -2903,8 +2904,6 @@ struct VehicleDrawInfo
ImageId imageId;
};
static VehicleDrawInfo _sprites_to_draw[144];
/**
*
* rct2: 0x006B2502
@@ -2931,11 +2930,13 @@ static void WindowRideVehicleScrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
// For each train
for (int32_t i = 0; i < ride->num_vehicles; i++)
{
VehicleDrawInfo* nextSpriteToDraw = _sprites_to_draw;
VehicleDrawInfo trainCarImages[OpenRCT2::Limits::MaxCarsPerTrain];
VehicleDrawInfo* nextSpriteToDraw = trainCarImages;
int32_t x = startX;
int32_t y = startY;
// For each car in train
static_assert(std::numeric_limits<decltype(ride->num_cars_per_train)>::max() <= std::size(trainCarImages));
for (int32_t j = 0; j < ride->num_cars_per_train; j++)
{
rideVehicleEntry = &rideEntry
@@ -2985,7 +2986,7 @@ static void WindowRideVehicleScrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
}
VehicleDrawInfo* current = nextSpriteToDraw;
while (--current >= _sprites_to_draw)
while (--current >= trainCarImages)
gfx_draw_sprite(dpi, current->imageId, { current->x, current->y });
startX += 36;