Fix #11655: Crash due to NWidgetMatrix modifying widget->index. (#11657)

NWidgetMatrix modifies its child widget's index to indicate which element
is to be drawn, which now causes issues with code that does not know about
stuffing extra data into the index.

Instead, let NWidgetMatrix store the currently processing element, and
retrieve this information from the matrix widget while child widgets are
being drawn.

This means only widgets that are children of NWidgetMatrix need to know
anything about their extra data.
This commit is contained in:
Peter Nelson
2023-12-30 18:24:26 +00:00
committed by GitHub
parent 1e60734660
commit 6215e9bf77
5 changed files with 40 additions and 35 deletions

View File

@@ -1409,7 +1409,7 @@ public:
void DrawWidget(const Rect &r, WidgetID widget) const override
{
switch (GB(widget, 0, 16)) {
switch (widget) {
case WID_BROS_STATION_NE:
case WID_BROS_STATION_SE:
case WID_BROS_STATION_SW:
@@ -1451,7 +1451,7 @@ public:
}
case WID_BROS_IMAGE: {
uint16_t type = GB(widget, 16, 16);
uint16_t type = this->GetWidget<NWidgetMatrix>(WID_BROS_MATRIX)->GetCurrentElement();
assert(type < _roadstop_gui_settings.roadstop_count);
const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(type);
@@ -1497,7 +1497,7 @@ public:
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
switch (GB(widget, 0, 16)) {
switch (widget) {
case WID_BROS_STATION_NE:
case WID_BROS_STATION_SE:
case WID_BROS_STATION_SW:
@@ -1549,7 +1549,7 @@ public:
}
case WID_BROS_IMAGE: {
uint16_t y = GB(widget, 16, 16);
uint16_t y = this->GetWidget<NWidgetMatrix>(WID_BROS_MATRIX)->GetCurrentElement();
if (y >= _roadstop_gui_settings.roadstop_count) return;
const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(y);