From f2c31fae117815c3c610edcccd9f33f8737dedd6 Mon Sep 17 00:00:00 2001 From: Lexxie9952 <32187224+Lexxie9952@users.noreply.github.com> Date: Sat, 10 Feb 2024 06:19:49 -0800 Subject: [PATCH] Fixed a crash when city removal left a unit stranded RM#81 https://redmine.freeciv.org/issues/81 author: @cazfi (nullptr changed to NULL by me) --- freeciv/freeciv/server/citytools.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/freeciv/freeciv/server/citytools.c b/freeciv/freeciv/server/citytools.c index e4573d824..b6e8806db 100644 --- a/freeciv/freeciv/server/citytools.c +++ b/freeciv/freeciv/server/citytools.c @@ -3464,14 +3464,17 @@ void city_landlocked_sell_coastal_improvements(struct tile *ptile) ****************************************************************************/ void city_refresh_vision(struct city *pcity) { - v_radius_t vision_radius_sq = V_RADIUS( - (short int) get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ, V_MAIN), - (short int) get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ, V_INVIS), - (short int) get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ, V_SUBSURFACE) - ); - - vision_change_sight(pcity->server.vision, vision_radius_sq); - ASSERT_VISION(pcity->server.vision); + if (pcity->server.vision != NULL) { + + v_radius_t vision_radius_sq = V_RADIUS( + (short int) get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ, V_MAIN), + (short int) get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ, V_INVIS), + (short int) get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ, V_SUBSURFACE) + ); + + vision_change_sight(pcity->server.vision, vision_radius_sq); + ASSERT_VISION(pcity->server.vision); + } } /************************************************************************//** @@ -3576,8 +3579,11 @@ bool city_map_update_radius_sq(struct city *pcity) city_refresh_vision(pcity); } - /* if city is under AI control update it */ - adv_city_update(pcity); + /* City removal might be ongoing, and advisor data already deleted */ + if (pcity->server.adv != NULL) { + /* If city is under AI control, update it */ + adv_city_update(pcity); + } notify_player(city_owner(pcity), city_tile(pcity), E_CITY_RADIUS_SQ, ftc_server, _("The size of the city map of %s is %s."),