From 38ea7958eb2b9273fa0e3144a697e08fe2e78476 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 25 Apr 2022 14:23:29 +0300 Subject: [PATCH 49/49] Tilespec: Setup citizen sets as ruleset is received Previously citizen sets were set only when ruleset data was already correct when the tileset was initially loaded. The cases where the ruleset is received afterwards left the tileset to wrong state, often leading to a crash. See osdn #44461 Signed-off-by: Marko Lindqvist --- client/tilespec.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/client/tilespec.c b/client/tilespec.c index 9711c281fd..280dcc7626 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -1449,19 +1449,6 @@ bool tilespec_reread(const char *new_tileset_name, for (id = 0; id < game.control.styles_count; id++) { tileset_setup_city_tiles(tileset, id); - const char *style_name = city_style_rule_name(id); - - tileset_setup_citizen_types(tileset, - &tileset->sprites.style_citizen_sets.sets[id], - city_styles[id].citizens_graphic, - style_name, FALSE); - specialist_type_iterate(sp) { - tileset_setup_specialist_type(tileset, - &tileset->sprites.style_citizen_sets.sets[id], - sp, - city_styles[id].citizens_graphic, - style_name, FALSE); - } specialist_type_iterate_end; } if (state < C_S_RUNNING) { @@ -6250,6 +6237,7 @@ void tileset_setup_city_tiles(struct tileset *t, int style) { if (style == game.control.styles_count - 1) { int i; + const char *style_name = city_style_rule_name(style); /* Free old sprites */ free_city_sprite(t->sprites.city.tile); @@ -6275,6 +6263,18 @@ void tileset_setup_city_tiles(struct tileset *t, int style) t->sprites.city.occupied = load_city_sprite(t, "occupied"); + tileset_setup_citizen_types(t, + &t->sprites.style_citizen_sets.sets[style], + city_styles[style].citizens_graphic, + style_name, FALSE); + specialist_type_iterate(sp) { + tileset_setup_specialist_type(t, + &t->sprites.style_citizen_sets.sets[style], + sp, + city_styles[style].citizens_graphic, + style_name, FALSE); + } specialist_type_iterate_end; + for (style = 0; style < game.control.styles_count; style++) { if (t->sprites.city.tile->styles[style].land_num_thresholds == 0) { tileset_error(LOG_FATAL, _("City style \"%s\": no city graphics."), @@ -6507,6 +6507,8 @@ struct sprite *get_citizen_sprite(const struct tileset *t, if (pcity != NULL) { int style = style_of_city(pcity); + fc_assert(t->sprites.style_citizen_sets.sets != NULL); + graphic = get_citizen_graphic(&t->sprites.style_citizen_sets.sets[style], type); @@ -7259,6 +7261,14 @@ void tileset_ruleset_reset(struct tileset *t) extra_type_list_destroy(t->flagged_bases_list); t->flagged_bases_list = extra_type_list_new(); } + + if (t->sprites.style_citizen_sets.sets != NULL) { + free(t->sprites.style_citizen_sets.sets); + } + + t->sprites.style_citizen_sets.sets + = fc_malloc(game.control.styles_count + * sizeof(t->sprites.style_citizen_sets.sets[0])); } /************************************************************************//** -- 2.35.1