Fixed a crash caused by the 1.2 code path getting a YV12 texture. :)

This commit is contained in:
Sam Lantinga 2011-02-12 08:17:58 -08:00
parent e74e437b3c
commit ba0ff6d7c8
2 changed files with 19 additions and 7 deletions

View file

@ -206,12 +206,22 @@ static Uint32
GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format) GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format)
{ {
Uint32 i; Uint32 i;
SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
/* We just want to match the first format that has the same channels */ if (SDL_ISPIXELFORMAT_FOURCC(format)) {
for (i = 0; i < renderer->info.num_texture_formats; ++i) { /* Look for an exact match */
if (SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) { for (i = 0; i < renderer->info.num_texture_formats; ++i) {
return renderer->info.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]; return renderer->info.texture_formats[0];
@ -313,7 +323,8 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
} }
format = renderer->info.texture_formats[0]; format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) { 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]; format = renderer->info.texture_formats[i];
break; break;
} }

View file

@ -274,7 +274,8 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix
/* Find the first format without an alpha channel */ /* Find the first format without an alpha channel */
*format = info.texture_formats[0]; *format = info.texture_formats[0];
for (i = 0; i < info.num_texture_formats; ++i) { 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]; *format = info.texture_formats[i];
break; break;
} }