From 0ca36f9d453a71b15b41e2ec75148188217832f5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 18 Mar 2023 18:07:05 +0200 Subject: [PATCH 15/15] load_sprite(): Fix crash after failed gfx file load Reported by ddeanbrown See osdn #47318 Signed-off-by: Marko Lindqvist --- client/tilespec.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/tilespec.c b/client/tilespec.c index f603ece691..5fdab36087 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -2602,19 +2602,24 @@ static struct sprite *load_sprite(struct tileset *t, const char *tag_name, if (!ss->sprite) { /* If the sprite hasn't been loaded already, then load it. */ fc_assert(ss->ref_count == 0); + if (ss->file) { int w, h; struct sprite *s; if (scale) { s = load_gfx_file(ss->file); - get_sprite_dimensions(s, &w, &h); - ss->sprite = crop_sprite(s, 0, 0, w, - h, NULL, -1, -1, t->scale, smooth); - free_sprite(s); + + if (s != NULL) { + get_sprite_dimensions(s, &w, &h); + ss->sprite = crop_sprite(s, 0, 0, w, + h, NULL, -1, -1, t->scale, smooth); + free_sprite(s); + } } else { ss->sprite = load_gfx_file(ss->file); } + if (!ss->sprite) { tileset_error(LOG_FATAL, tileset_name_get(t), _("Couldn't load gfx file \"%s\" for sprite '%s'."), -- 2.39.2