[Commits] SDL: Fixed bug 4264 - SDL_CreateTextureFromSurface generates err...

libsdl.org revision control commits-owner at libsdl.org
Mon Sep 24 16:42:07 PDT 2018


details:   https://hg.libsdl.org/SDL/rev/5486557ca8d9
changeset: 12204:5486557ca8d9
user:      Sam Lantinga <slouken at libsdl.org>
date:      Mon Sep 24 16:41:55 2018 -0700
description:
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.

diffstat:

 include/SDL_surface.h             |   7 +++++++
 src/dynapi/SDL_dynapi_overrides.h |   1 +
 src/dynapi/SDL_dynapi_procs.h     |   1 +
 src/render/SDL_render.c           |   2 +-
 src/video/SDL_surface.c           |  14 ++++++++++++++
 5 files changed, 24 insertions(+), 1 deletions(-)

diffs (69 lines):

diff -r b527a6a49bfd -r 5486557ca8d9 include/SDL_surface.h
--- a/include/SDL_surface.h	Mon Sep 24 16:33:14 2018 -0700
+++ b/include/SDL_surface.h	Mon Sep 24 16:41:55 2018 -0700
@@ -249,6 +249,13 @@
                                             int flag, Uint32 key);
 
 /**
+ *  \brief Returns whether the surface has a color key
+ *
+ *  \return SDL_TRUE if the surface has a color key, or SDL_FALSE if the surface is NULL or has no color key
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasColorKey(SDL_Surface * surface);
+
+/**
  *  \brief Gets the color key (transparent pixel) in a blittable surface.
  *
  *  \param surface The surface to update
diff -r b527a6a49bfd -r 5486557ca8d9 src/dynapi/SDL_dynapi_overrides.h
--- a/src/dynapi/SDL_dynapi_overrides.h	Mon Sep 24 16:33:14 2018 -0700
+++ b/src/dynapi/SDL_dynapi_overrides.h	Mon Sep 24 16:41:55 2018 -0700
@@ -696,3 +696,4 @@
 #define SDL_SensorUpdate SDL_SensorUpdate_REAL
 #define SDL_IsTablet SDL_IsTablet_REAL
 #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
+#define SDL_HasColorKey SDL_HasColorKey_REAL
diff -r b527a6a49bfd -r 5486557ca8d9 src/dynapi/SDL_dynapi_procs.h
--- a/src/dynapi/SDL_dynapi_procs.h	Mon Sep 24 16:33:14 2018 -0700
+++ b/src/dynapi/SDL_dynapi_procs.h	Mon Sep 24 16:41:55 2018 -0700
@@ -738,3 +738,4 @@
 SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),)
 SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
 SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasColorKey,(SDL_Surface *a),(a),return)
diff -r b527a6a49bfd -r 5486557ca8d9 src/render/SDL_render.c
--- a/src/render/SDL_render.c	Mon Sep 24 16:33:14 2018 -0700
+++ b/src/render/SDL_render.c	Mon Sep 24 16:41:55 2018 -0700
@@ -649,7 +649,7 @@
 
     /* See what the best texture format is */
     fmt = surface->format;
-    if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) {
+    if (fmt->Amask || (SDL_HasColorKey(surface) && SDL_GetColorKey(surface, NULL) == 0)) {
         needAlpha = SDL_TRUE;
     } else {
         needAlpha = SDL_FALSE;
diff -r b527a6a49bfd -r 5486557ca8d9 src/video/SDL_surface.c
--- a/src/video/SDL_surface.c	Mon Sep 24 16:33:14 2018 -0700
+++ b/src/video/SDL_surface.c	Mon Sep 24 16:41:55 2018 -0700
@@ -292,6 +292,20 @@
     return 0;
 }
 
+SDL_bool
+SDL_HasColorKey(SDL_Surface * surface)
+{
+    if (!surface) {
+        return SDL_FALSE;
+    }
+
+    if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
+        return SDL_FALSE;
+    }
+
+	return SDL_TRUE;
+}
+
 int
 SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
 {


More information about the commits mailing list