Skip to content

Commit

Permalink
Updated for SDL3 change of SDL_SetError returning SDL_FALSE, not -1
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Aug 27, 2024
1 parent 2b69c36 commit c9d7d4b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/showimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ int main(int argc, char *argv[])
} else if (ext && SDL_strcasecmp(ext, ".png") == 0) {
result = IMG_SavePNG(surface, saveFile);
} else {
result = SDL_SetError("Unknown save file type");
SDL_SetError("Unknown save file type");
result = -1;
}
if (result < 0) {
SDL_Log("Couldn't save %s: %s\n", saveFile, SDL_GetError());
Expand Down
6 changes: 4 additions & 2 deletions src/IMG_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ int IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int qu
int result = -1;

if (!dst) {
return IMG_SetError("Passed NULL dst");
IMG_SetError("Passed NULL dst");
return -1;
}

#ifdef SDL_IMAGE_SAVE_AVIF
Expand All @@ -761,7 +762,8 @@ int IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int qu
#else
(void) surface;
(void) quality;
result = IMG_SetError("SDL_image built without AVIF save support");
IMG_SetError("SDL_image built without AVIF save support");
result = -1;
#endif

if (closeio) {
Expand Down
9 changes: 6 additions & 3 deletions src/IMG_jpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ static int JPEG_SaveJPEG_IO(struct savejpeg_vars *vars, SDL_Surface *jpeg_surfac
/* If we get here, libjpeg found an error */
lib.jpeg_destroy_compress(&vars->cinfo);
SDL_SeekIO(dst, vars->original_offset, SDL_IO_SEEK_SET);
return IMG_SetError("Error saving JPEG with libjpeg");
IMG_SetError("Error saving JPEG with libjpeg");
return -1;
}

lib.jpeg_create_compress(&vars->cinfo);
Expand Down Expand Up @@ -771,7 +772,8 @@ int IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int qua
(void)quality;

if (!dst) {
return IMG_SetError("Passed NULL dst");
IMG_SetError("Passed NULL dst");
return -1;
}

#if SDL_IMAGE_SAVE_JPG
Expand All @@ -788,7 +790,8 @@ int IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int qua
#endif

#else
result = IMG_SetError("SDL_image built without JPEG save support");
IMG_SetError("SDL_image built without JPEG save support");
result = -1;
#endif

if (closeio) {
Expand Down
15 changes: 10 additions & 5 deletions src/IMG_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD

vars->png_ptr = lib.png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (vars->png_ptr == NULL) {
return IMG_SetError("Couldn't allocate memory for PNG file or incompatible PNG dll");
IMG_SetError("Couldn't allocate memory for PNG file or incompatible PNG dll");
return -1;
}

vars->info_ptr = lib.png_create_info_struct(vars->png_ptr);
Expand Down Expand Up @@ -768,7 +769,8 @@ static int IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst)
int result = -1;

if (!dst) {
return IMG_SetError("Passed NULL dst");
IMG_SetError("Passed NULL dst");
return -1;
}

if (surface->format == png_format) {
Expand All @@ -786,7 +788,8 @@ static int IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst)
}
mz_free(png); /* calls SDL_free() */
} else {
return IMG_SetError("Failed to convert and save image");
IMG_SetError("Failed to convert and save image");
return -1;
}
return result;
}
Expand All @@ -809,7 +812,8 @@ int IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio)
int result = -1;

if (!dst) {
return IMG_SetError("Passed NULL dst");
IMG_SetError("Passed NULL dst");
return -1;
}

#if SDL_IMAGE_SAVE_PNG
Expand All @@ -826,7 +830,8 @@ int IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio)
#endif

#else
result = IMG_SetError("SDL_image built without PNG save support");
IMG_SetError("SDL_image built without PNG save support");
result = -1;
#endif

if (closeio) {
Expand Down

0 comments on commit c9d7d4b

Please sign in to comment.