From e798c515ad77e443f9c6fc455b1a1ba4ff268da3 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 23 Apr 2023 03:32:46 +0300 Subject: [PATCH 33/33] calc_activity(): Tolerate inconsistent unit act / tgt Qt-client was crashing when it had inconsistent state in the middle of updates coming from the server. Reported by bard See osdn #47882 Signed-off-by: Marko Lindqvist --- common/clientutils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/clientutils.c b/common/clientutils.c index 44a24ba537..abde999a95 100644 --- a/common/clientutils.c +++ b/common/clientutils.c @@ -73,13 +73,19 @@ static void calc_activity(struct actcalc *calc, const struct tile *ptile, continue; } - if (is_build_activity(act)) { + /* Client needs check for activity_target even when the + * activity is a build activity, and SHOULD have target. + * Server may still be sending more information about tile or + * unit activity changes, and client data is not yet consistent. */ + if (is_build_activity(act) + && punit->activity_target != NULL) { int eidx = extra_index(punit->activity_target); t->extra_total[eidx][act] += punit->activity_count; t->extra_total[eidx][act] += get_activity_rate_this_turn(punit); t->extra_units[eidx][act] += get_activity_rate(punit); - } else if (is_clean_activity(act)) { + } else if (is_clean_activity(act) + && punit->activity_target != NULL) { int eidx = extra_index(punit->activity_target); t->rmextra_total[eidx][act] += punit->activity_count; -- 2.39.2