Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #17073: Writing out of bounds when trains have over 144 cars #17074

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
9 changes: 5 additions & 4 deletions src/openrct2-ui/windows/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -2903,8 +2904,6 @@ struct VehicleDrawInfo
ImageId imageId;
};

static VehicleDrawInfo _sprites_to_draw[144];

/**
*
* rct2: 0x006B2502
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down