From 7c8adf46c8f6662cff7c0b8e232a1d909e4e752a 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 | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/client/tilespec.c b/client/tilespec.c index 9711c281fd..36b7912bca 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) { @@ -6248,6 +6235,8 @@ int fill_sprite_array(struct tileset *t, ****************************************************************************/ void tileset_setup_city_tiles(struct tileset *t, int style) { + const char *style_name = city_style_rule_name(style); + if (style == game.control.styles_count - 1) { int i; @@ -6274,7 +6263,21 @@ void tileset_setup_city_tiles(struct tileset *t, int style) t->sprites.city.single_wall = load_city_sprite(t, "wall"); 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; + + if (style == game.control.styles_count - 1) { 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 +6510,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 +7264,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