Better error reporting in allocating a pixel format.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 21:49:52 -0800
changeset 5433 1b6eee840e26
parent 5432 b3913347f1d7
child 5434 fb5e9db92a77
Better error reporting in allocating a pixel format.
src/video/SDL_pixels.c
--- a/src/video/SDL_pixels.c	Sun Mar 06 21:47:48 2011 -0800
+++ b/src/video/SDL_pixels.c	Sun Mar 06 21:49:52 2011 -0800
@@ -85,7 +85,7 @@
 
     /* This function doesn't work with FourCC pixel formats */
     if (SDL_ISPIXELFORMAT_FOURCC(format)) {
-        SDL_SetError("Unknown pixel format");
+        SDL_SetError("FOURCC pixel formats are not supported");
         return SDL_FALSE;
     }
  
@@ -418,11 +418,6 @@
 {
     SDL_PixelFormat *format;
 
-    if (SDL_ISPIXELFORMAT_FOURCC(pixel_format)) {
-        SDL_SetError("FOURCC pixel formats are not supported");
-        return NULL;
-    }
-
     /* Look it up in our list of previously allocated formats */
     for (format = formats; format; format = format->next) {
         if (pixel_format == format->format) {
@@ -435,9 +430,12 @@
     format = SDL_malloc(sizeof(*format));
     if (format == NULL) {
         SDL_OutOfMemory();
-        return (NULL);
+        return NULL;
     }
-    SDL_InitFormat(format, pixel_format);
+    if (SDL_InitFormat(format, pixel_format) < 0) {
+        SDL_free(format);
+        return NULL;
+    }
 
     if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
         /* Cache the RGB formats */
@@ -456,7 +454,6 @@
 
     if (!SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
                                     &Rmask, &Gmask, &Bmask, &Amask)) {
-        SDL_SetError("Unknown pixel format");
         return -1;
     }