Fixed a crash caused by the 1.2 code path getting a YV12 texture. :)
authorSam Lantinga
Sat, 12 Feb 2011 08:17:58 -0800
changeset 5268c5a04f3c3908
parent 5267 93ea62a5ba8f
child 5269 11bd1585efb5
Fixed a crash caused by the 1.2 code path getting a YV12 texture. :)
src/render/SDL_render.c
src/video/SDL_video.c
     1.1 --- a/src/render/SDL_render.c	Sat Feb 12 08:17:37 2011 -0800
     1.2 +++ b/src/render/SDL_render.c	Sat Feb 12 08:17:58 2011 -0800
     1.3 @@ -206,12 +206,22 @@
     1.4  GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format)
     1.5  {
     1.6      Uint32 i;
     1.7 -    SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
     1.8  
     1.9 -    /* We just want to match the first format that has the same channels */
    1.10 -    for (i = 0; i < renderer->info.num_texture_formats; ++i) {
    1.11 -        if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
    1.12 -            return renderer->info.texture_formats[i];
    1.13 +    if (SDL_ISPIXELFORMAT_FOURCC(format)) {
    1.14 +        /* Look for an exact match */
    1.15 +        for (i = 0; i < renderer->info.num_texture_formats; ++i) {
    1.16 +            if (renderer->info.texture_formats[i] == format) {
    1.17 +                return renderer->info.texture_formats[i];
    1.18 +            }
    1.19 +        }
    1.20 +    } else {
    1.21 +        SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
    1.22 +
    1.23 +        /* We just want to match the first format that has the same channels */
    1.24 +        for (i = 0; i < renderer->info.num_texture_formats; ++i) {
    1.25 +            if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
    1.26 +                return renderer->info.texture_formats[i];
    1.27 +            }
    1.28          }
    1.29      }
    1.30      return renderer->info.texture_formats[0];
    1.31 @@ -313,7 +323,8 @@
    1.32      }
    1.33      format = renderer->info.texture_formats[0];
    1.34      for (i = 0; i < renderer->info.num_texture_formats; ++i) {
    1.35 -        if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
    1.36 +        if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
    1.37 +            SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
    1.38              format = renderer->info.texture_formats[i];
    1.39              break;
    1.40          }
     2.1 --- a/src/video/SDL_video.c	Sat Feb 12 08:17:37 2011 -0800
     2.2 +++ b/src/video/SDL_video.c	Sat Feb 12 08:17:58 2011 -0800
     2.3 @@ -274,7 +274,8 @@
     2.4      /* Find the first format without an alpha channel */
     2.5      *format = info.texture_formats[0];
     2.6      for (i = 0; i < info.num_texture_formats; ++i) {
     2.7 -        if (!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
     2.8 +        if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
     2.9 +            !SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
    2.10              *format = info.texture_formats[i];
    2.11              break;
    2.12          }