Skip to content
Permalink
Browse files

Fixed failing SDL_ConvertSurface() when blit has failed.

Some blit combination are not supported (eg ARGB8888 -> SDL_PIXELFORMAT_INDEX1MSB)
So prevent SDL_ConvertSurface from creating a broken surface, which cannot be blitted
  • Loading branch information
1bsyl committed Jan 30, 2019
1 parent a052d81 commit 5b07148f73ceae19b8bc0f3d6b8f9e72885dd4ce
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/video/SDL_surface.c
@@ -957,6 +957,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
Uint32 copy_flags;
SDL_Color copy_color;
SDL_Rect bounds;
int ret;

if (!surface) {
SDL_InvalidParamError("surface");
@@ -1017,7 +1018,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
bounds.y = 0;
bounds.w = surface->w;
bounds.h = surface->h;
SDL_LowerBlit(surface, &bounds, convert, &bounds);
ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);

/* Clean up the original surface, and update converted surface */
convert->map->info.r = copy_color.r;
@@ -1035,6 +1036,13 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
surface->map->info.a = copy_color.a;
surface->map->info.flags = copy_flags;
SDL_InvalidateMap(surface->map);

/* SDL_LowerBlit failed, and so the conversion */
if (ret < 0) {
SDL_FreeSurface(convert);
return NULL;
}

if (copy_flags & SDL_COPY_COLORKEY) {
SDL_bool set_colorkey_by_color = SDL_FALSE;
SDL_bool ignore_alpha = SDL_TRUE; /* Ignore, or not, alpha in colorkey comparison */

0 comments on commit 5b07148

Please sign in to comment.