Better error reporting in allocating a pixel format.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 21:49:52 -0800
changeset 54331b6eee840e26
parent 5432 b3913347f1d7
child 5434 fb5e9db92a77
Better error reporting in allocating a pixel format.
src/video/SDL_pixels.c
     1.1 --- a/src/video/SDL_pixels.c	Sun Mar 06 21:47:48 2011 -0800
     1.2 +++ b/src/video/SDL_pixels.c	Sun Mar 06 21:49:52 2011 -0800
     1.3 @@ -85,7 +85,7 @@
     1.4  
     1.5      /* This function doesn't work with FourCC pixel formats */
     1.6      if (SDL_ISPIXELFORMAT_FOURCC(format)) {
     1.7 -        SDL_SetError("Unknown pixel format");
     1.8 +        SDL_SetError("FOURCC pixel formats are not supported");
     1.9          return SDL_FALSE;
    1.10      }
    1.11   
    1.12 @@ -418,11 +418,6 @@
    1.13  {
    1.14      SDL_PixelFormat *format;
    1.15  
    1.16 -    if (SDL_ISPIXELFORMAT_FOURCC(pixel_format)) {
    1.17 -        SDL_SetError("FOURCC pixel formats are not supported");
    1.18 -        return NULL;
    1.19 -    }
    1.20 -
    1.21      /* Look it up in our list of previously allocated formats */
    1.22      for (format = formats; format; format = format->next) {
    1.23          if (pixel_format == format->format) {
    1.24 @@ -435,9 +430,12 @@
    1.25      format = SDL_malloc(sizeof(*format));
    1.26      if (format == NULL) {
    1.27          SDL_OutOfMemory();
    1.28 -        return (NULL);
    1.29 +        return NULL;
    1.30      }
    1.31 -    SDL_InitFormat(format, pixel_format);
    1.32 +    if (SDL_InitFormat(format, pixel_format) < 0) {
    1.33 +        SDL_free(format);
    1.34 +        return NULL;
    1.35 +    }
    1.36  
    1.37      if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
    1.38          /* Cache the RGB formats */
    1.39 @@ -456,7 +454,6 @@
    1.40  
    1.41      if (!SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
    1.42                                      &Rmask, &Gmask, &Bmask, &Amask)) {
    1.43 -        SDL_SetError("Unknown pixel format");
    1.44          return -1;
    1.45      }
    1.46