Skip to content

Commit

Permalink
Fixed failing SDL_ConvertSurface() when blit has failed.
Browse files Browse the repository at this point in the history
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 5b07148
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/video/SDL_surface.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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 */
Expand Down

0 comments on commit 5b07148

Please sign in to comment.