Skip to content

Commit

Permalink
Server: Backport 0017-Fix-city-removal-server-crashes.patch
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Lindqvist <[email protected]>
  • Loading branch information
cazfi committed Dec 28, 2023
1 parent 1f42f88 commit 97710d8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions freeciv/apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# 0014-Improve-savemain.c-coding-style.patch
# Baseline for freeciv-web patches
# RM #79
# 0017-Fix-city-removal-server-crashes.patch
# Crash fix
# RM #81

# Not in the upstream Freeciv server
# ----------------------------------
Expand Down Expand Up @@ -48,6 +51,7 @@ declare -a PATCHLIST=(
"backports/0029-universal_value_initial-Fix-switch-case-fall-through"
"backports/0031-Meson-Enable-implicit-fallthrough-compiler-warnings"
"backports/0014-Improve-savemain.c-coding-style"
"backports/0017-Fix-city-removal-server-crashes"
"meson_webperimental"
"metachange"
"text_fixes"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From 37508b45f7591f3acb749afb223aeefcaeb76749 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <[email protected]>
Date: Wed, 27 Dec 2023 15:11:56 +0200
Subject: [PATCH 17/17] Fix city removal server crashes

When city removal wipes a unit that's not homed to the city,
but on the same tile, recursive city refresh was crashing
due to city vision and advisor data being already deleted.

See RM #81

Signed-off-by: Marko Lindqvist <[email protected]>
---
server/citytools.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/server/citytools.c b/server/citytools.c
index f760deb3e0..87917e0b77 100644
--- a/server/citytools.c
+++ b/server/citytools.c
@@ -3416,11 +3416,13 @@ void city_landlocked_sell_coastal_improvements(struct tile *ptile)
****************************************************************************/
void city_refresh_vision(struct city *pcity)
{
- v_radius_t vision_radius_sq
- = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2);
+ if (pcity->server.vision != nullptr) {
+ v_radius_t vision_radius_sq
+ = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2);

- vision_change_sight(pcity->server.vision, vision_radius_sq);
- ASSERT_VISION(pcity->server.vision);
+ vision_change_sight(pcity->server.vision, vision_radius_sq);
+ ASSERT_VISION(pcity->server.vision);
+ }
}

/************************************************************************//**
@@ -3525,8 +3527,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 != nullptr) {
+ /* 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."),
--
2.43.0

0 comments on commit 97710d8

Please sign in to comment.