Fixed a crash caused by the 1.2 code path getting a YV12 texture. :)
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Feb 2011 08:17:58 -0800
changeset 5268 c5a04f3c3908
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
--- a/src/render/SDL_render.c	Sat Feb 12 08:17:37 2011 -0800
+++ b/src/render/SDL_render.c	Sat Feb 12 08:17:58 2011 -0800
@@ -206,12 +206,22 @@
 GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format)
 {
     Uint32 i;
-    SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
 
-    /* We just want to match the first format that has the same channels */
-    for (i = 0; i < renderer->info.num_texture_formats; ++i) {
-        if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
-            return renderer->info.texture_formats[i];
+    if (SDL_ISPIXELFORMAT_FOURCC(format)) {
+        /* Look for an exact match */
+        for (i = 0; i < renderer->info.num_texture_formats; ++i) {
+            if (renderer->info.texture_formats[i] == format) {
+                return renderer->info.texture_formats[i];
+            }
+        }
+    } else {
+        SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
+
+        /* We just want to match the first format that has the same channels */
+        for (i = 0; i < renderer->info.num_texture_formats; ++i) {
+            if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
+                return renderer->info.texture_formats[i];
+            }
         }
     }
     return renderer->info.texture_formats[0];
@@ -313,7 +323,8 @@
     }
     format = renderer->info.texture_formats[0];
     for (i = 0; i < renderer->info.num_texture_formats; ++i) {
-        if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
+        if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
+            SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
             format = renderer->info.texture_formats[i];
             break;
         }
--- a/src/video/SDL_video.c	Sat Feb 12 08:17:37 2011 -0800
+++ b/src/video/SDL_video.c	Sat Feb 12 08:17:58 2011 -0800
@@ -274,7 +274,8 @@
     /* Find the first format without an alpha channel */
     *format = info.texture_formats[0];
     for (i = 0; i < info.num_texture_formats; ++i) {
-        if (!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
+        if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
+            !SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
             *format = info.texture_formats[i];
             break;
         }