diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 269d64da0..7a22fb80d 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -38,7 +38,8 @@ https://tuxpaint.org/ AppData. TOYAMA Shin-ichi - * "Foam" magic tool -- avoid crash if image data cannot be loaded. + * Avoid crash in some Magic tools if image data cannot be loaded. + (Foam, Fretwork, Rails) Bill Kendrick * Localization Updates: diff --git a/magic/src/fretwork.c b/magic/src/fretwork.c index 6daa8c86f..e4eeffcaa 100644 --- a/magic/src/fretwork.c +++ b/magic/src/fretwork.c @@ -1,7 +1,7 @@ /* Draws fretwork - Last updated: April 19, 2023 + Last updated: November 12, 2023 */ #include "tp_magic_api.h" @@ -162,6 +162,23 @@ int fretwork_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED) fretwork_four_back = IMG_Load(fretwork_images[2]); fretwork_corner_back = IMG_Load(fretwork_images[3]); + if (fretwork_one == NULL || fretwork_one_back == NULL) { + fprintf(stderr, "Cannot load %s\n", fretwork_images[0]); + return(0); + } + if (fretwork_three == NULL || fretwork_three_back == NULL) { + fprintf(stderr, "Cannot load %s\n", fretwork_images[1]); + return(0); + } + if (fretwork_four == NULL || fretwork_four_back == NULL) { + fprintf(stderr, "Cannot load %s\n", fretwork_images[2]); + return(0); + } + if (fretwork_corner == NULL || fretwork_corner_back == NULL) { + fprintf(stderr, "Cannot load %s\n", fretwork_images[3]); + return(0); + } + img_w = fretwork_one->w; img_h = fretwork_one->h; diff --git a/magic/src/rails.c b/magic/src/rails.c index d7eeab3e2..38d93b73a 100644 --- a/magic/src/rails.c +++ b/magic/src/rails.c @@ -3,7 +3,7 @@ Draw train tracks. - Last updated: April 19, 2023 + Last updated: November 12, 2023 */ #include "tp_magic_api.h" #include "SDL_image.h" @@ -122,6 +122,23 @@ int rails_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED) rails_four = IMG_Load(rails_images[2]); rails_corner = IMG_Load(rails_images[3]); + if (rails_one == NULL) { + fprintf(stderr, "Can't load image %s\n", rails_images[0]); + return(0); + } + if (rails_three == NULL) { + fprintf(stderr, "Can't load image %s\n", rails_images[1]); + return(0); + } + if (rails_four == NULL) { + fprintf(stderr, "Can't load image %s\n", rails_images[2]); + return(0); + } + if (rails_corner == NULL) { + fprintf(stderr, "Can't load image %s\n", rails_images[3]); + return(0); + } + img_w = rails_one->w; img_h = rails_one->h;