Fixed bug 4264 - SDL_CreateTextureFromSurface generates error message but returns ok
authorSam Lantinga <slouken@libsdl.org>
Mon, 24 Sep 2018 16:41:55 -0700
changeset 122045486557ca8d9
parent 12203 b527a6a49bfd
child 12205 483789136c52
Fixed bug 4264 - SDL_CreateTextureFromSurface generates error message but returns ok

Anthony @ POW Games

SDL_CreateTextureFromSurface makes an internal call to SDL_GetColorKey which can return an error and spams the error log with "Surface doesn't have a colorkey" even though the original function didn't return an error.
include/SDL_surface.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/render/SDL_render.c
src/video/SDL_surface.c
     1.1 --- a/include/SDL_surface.h	Mon Sep 24 16:33:14 2018 -0700
     1.2 +++ b/include/SDL_surface.h	Mon Sep 24 16:41:55 2018 -0700
     1.3 @@ -249,6 +249,13 @@
     1.4                                              int flag, Uint32 key);
     1.5  
     1.6  /**
     1.7 + *  \brief Returns whether the surface has a color key
     1.8 + *
     1.9 + *  \return SDL_TRUE if the surface has a color key, or SDL_FALSE if the surface is NULL or has no color key
    1.10 + */
    1.11 +extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface);
    1.12 +
    1.13 +/**
    1.14   *  \brief Gets the color key (transparent pixel) in a blittable surface.
    1.15   *
    1.16   *  \param surface The surface to update
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Mon Sep 24 16:33:14 2018 -0700
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Mon Sep 24 16:41:55 2018 -0700
     2.3 @@ -696,3 +696,4 @@
     2.4  #define SDL_SensorUpdate SDL_SensorUpdate_REAL
     2.5  #define SDL_IsTablet SDL_IsTablet_REAL
     2.6  #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
     2.7 +#define SDL_HasColorKey SDL_HasColorKey_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Mon Sep 24 16:33:14 2018 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Mon Sep 24 16:41:55 2018 -0700
     3.3 @@ -738,3 +738,4 @@
     3.4  SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),)
     3.5  SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
     3.6  SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return)
     3.7 +SDL_DYNAPI_PROC(SDL_bool,SDL_HasColorKey,(SDL_Surface *a),(a),return)
     4.1 --- a/src/render/SDL_render.c	Mon Sep 24 16:33:14 2018 -0700
     4.2 +++ b/src/render/SDL_render.c	Mon Sep 24 16:41:55 2018 -0700
     4.3 @@ -649,7 +649,7 @@
     4.4  
     4.5      /* See what the best texture format is */
     4.6      fmt = surface->format;
     4.7 -    if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) {
     4.8 +    if (fmt->Amask || (SDL_HasColorKey(surface) && SDL_GetColorKey(surface, NULL) == 0)) {
     4.9          needAlpha = SDL_TRUE;
    4.10      } else {
    4.11          needAlpha = SDL_FALSE;
     5.1 --- a/src/video/SDL_surface.c	Mon Sep 24 16:33:14 2018 -0700
     5.2 +++ b/src/video/SDL_surface.c	Mon Sep 24 16:41:55 2018 -0700
     5.3 @@ -292,6 +292,20 @@
     5.4      return 0;
     5.5  }
     5.6  
     5.7 +SDL_bool
     5.8 +SDL_HasColorKey(SDL_Surface * surface)
     5.9 +{
    5.10 +    if (!surface) {
    5.11 +        return SDL_FALSE;
    5.12 +    }
    5.13 +
    5.14 +    if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
    5.15 +        return SDL_FALSE;
    5.16 +    }
    5.17 +
    5.18 +	return SDL_TRUE;
    5.19 +}
    5.20 +
    5.21  int
    5.22  SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
    5.23  {