Fixed failing SDL_ConvertSurface() when blit has failed.
authorSylvain Becker <sylvain.becker@gmail.com>
Wed, 30 Jan 2019 16:36:47 +0100
changeset 12584233b2a61cad1
parent 12583 338b02acfdfc
child 12585 dff36de37426
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
src/video/SDL_surface.c
     1.1 --- a/src/video/SDL_surface.c	Wed Jan 30 15:31:07 2019 +0100
     1.2 +++ b/src/video/SDL_surface.c	Wed Jan 30 16:36:47 2019 +0100
     1.3 @@ -957,6 +957,7 @@
     1.4      Uint32 copy_flags;
     1.5      SDL_Color copy_color;
     1.6      SDL_Rect bounds;
     1.7 +    int ret;
     1.8  
     1.9      if (!surface) {
    1.10          SDL_InvalidParamError("surface");
    1.11 @@ -1017,7 +1018,7 @@
    1.12      bounds.y = 0;
    1.13      bounds.w = surface->w;
    1.14      bounds.h = surface->h;
    1.15 -    SDL_LowerBlit(surface, &bounds, convert, &bounds);
    1.16 +    ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
    1.17  
    1.18      /* Clean up the original surface, and update converted surface */
    1.19      convert->map->info.r = copy_color.r;
    1.20 @@ -1035,6 +1036,13 @@
    1.21      surface->map->info.a = copy_color.a;
    1.22      surface->map->info.flags = copy_flags;
    1.23      SDL_InvalidateMap(surface->map);
    1.24 +
    1.25 +    /* SDL_LowerBlit failed, and so the conversion */
    1.26 +    if (ret < 0) {
    1.27 +        SDL_FreeSurface(convert);
    1.28 +        return NULL;
    1.29 +    }
    1.30 +
    1.31      if (copy_flags & SDL_COPY_COLORKEY) {
    1.32          SDL_bool set_colorkey_by_color = SDL_FALSE;
    1.33          SDL_bool ignore_alpha          = SDL_TRUE;  /* Ignore, or not, alpha in colorkey comparison */