From 132b2e59666e327e35add1131a4dbd5d3fabb576 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 13 Jul 2020 14:31:04 +0200 Subject: [PATCH] Fix #12071: Crash in Guest List when a guest dies (#12126) Send refresh guest list intent on peep removal Also added protection to guest list to prevent accessing invalid peeps --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/GuestList.cpp | 12 ++++++++++-- src/openrct2/peep/Peep.cpp | 9 +++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index fa67c6229e..d462dfd729 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -42,6 +42,7 @@ - Fix: [#11953] Incorrect banner text shade colour on wall text. - Fix: [#12062] Inconsistent lift hill sprites on Flying Coaster while inverted (original bug). - Fix: [#12068] Incorrect Entrance/Exit location on track design preview. Incorrect track design previews with track that contain diagonal track elements. +- Fix: [#12071] Crash in Guest List when a guest dies. - Fix: [#12093] Staff window tab animation was no longer updating. - Fix: [#12123] Long server descriptions are not cut off properly. - Fix: [#12211] Map Generator shows incorrect map sizes (e.g. "150 x 0"). diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 790d5fd65e..94ff0babd0 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -582,7 +582,11 @@ static void window_guest_list_scrollmousedown(rct_window* w, int32_t scrollIndex { if (i == 0) { - window_guest_open(GET_PEEP(spriteIndex)); + auto guest = GetEntity(spriteIndex); + if (guest != nullptr) + { + window_guest_open(guest); + } break; } i--; @@ -771,7 +775,11 @@ static void window_guest_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, } // Guest name - auto peep = GET_PEEP(spriteIndex); + auto peep = GetEntity(spriteIndex); + if (peep == nullptr) + { + continue; + } auto ft = Formatter::Common(); peep->FormatNameTo(ft); gfx_draw_string_left_clipped(dpi, format, gCommonFormatArgs, COLOUR_BLACK, { 0, y }, 113); diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 2a02de50b1..6817195b89 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -812,16 +812,14 @@ void peep_sprite_remove(Peep* peep) window_close_by_number(WC_FIRE_PROMPT, peep->sprite_identifier); + // Needed for invalidations after sprite removal + bool wasGuest = peep->AssignedPeepType == PEEP_TYPE_GUEST; if (peep->AssignedPeepType == PEEP_TYPE_GUEST) { - window_invalidate_by_class(WC_GUEST_LIST); - news_item_disable_news(NEWS_ITEM_PEEP_ON_RIDE, peep->sprite_index); } else { - window_invalidate_by_class(WC_STAFF_LIST); - gStaffModes[peep->StaffId] = 0; peep->AssignedPeepType = PEEP_TYPE_INVALID; staff_update_greyed_patrol_areas(); @@ -830,6 +828,9 @@ void peep_sprite_remove(Peep* peep) news_item_disable_news(NEWS_ITEM_PEEP, peep->sprite_index); } sprite_remove(peep); + + auto intent = Intent(wasGuest ? INTENT_ACTION_REFRESH_GUEST_LIST : INTENT_ACTION_REFRESH_STAFF_LIST); + context_broadcast_intent(&intent); } /**