From 84eb3fb0e01fc8ac4faa546143a76c630463741d Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 24 Nov 2025 11:22:58 +0000 Subject: [PATCH] Fix #14800: Incorrect register processing in GetCustomStationRelocation (#14801) ProcessRegisters must be called even if the sprite resolve result is not valid. A zero-length ResultSpriteGroup is valid because the output value is an offset, not a sprite ID within the ResultSpriteGroup. --- src/newgrf_station.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 358f6505d5..b5b5997dba 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -614,7 +614,9 @@ SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st { StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10); const auto *group = object.Resolve(); - if (group == nullptr || group->num_sprites == 0) return 0; + + /* A zero-length ResultSpriteGroup is valid because the output value is an offset, not a sprite ID within the ResultSpriteGroup. */ + if (group == nullptr) return 0; return group->sprite - SPR_RAIL_PLATFORM_Y_FRONT; } @@ -624,8 +626,12 @@ void GetCustomStationRelocation(SpriteLayoutProcessor &processor, const StationS for (uint8_t var10 : processor.Var10Values()) { object.callback_param1 = var10; const auto *group = object.Resolve(); - if (group == nullptr || group->num_sprites == 0) continue; - processor.ProcessRegisters(object, var10, group->sprite - SPR_RAIL_PLATFORM_Y_FRONT); + + /* ProcessRegisters must be called no matter the type of the sprite resolve result or whether it is valid. + * The sprite offset is only used for layouts with the SPRITE_MODIFIER_CUSTOM_SPRITE flag, however other aspects of layouts + * such as register operations must still be processed even if this flag is not set and the sprite offset is never used. + * A zero-length ResultSpriteGroup is valid because the output value is an offset, not a sprite ID within the ResultSpriteGroup. */ + processor.ProcessRegisters(object, var10, group != nullptr ? group->sprite - SPR_RAIL_PLATFORM_Y_FRONT : 0); } }