Copy the pixel data into the surface
authorBrian Palmer <brian@codekitchen.net>
Mon, 10 Jun 2019 16:42:52 -0700
changeset 652679fc3083485
parent 651 97e271eca329
child 653 d5baeefe5687
Copy the pixel data into the surface
It was getting immediately freed out from underneath the surface, SDL_CreateRGBSurfaceFrom does not copy the pixel data.
IMG.c
     1.1 --- a/IMG.c	Mon Jun 10 16:42:16 2019 -0700
     1.2 +++ b/IMG.c	Mon Jun 10 16:42:52 2019 -0700
     1.3 @@ -192,12 +192,16 @@
     1.4  
     1.5          if(data)
     1.6          {
     1.7 -            surf = SDL_CreateRGBSurfaceFrom(data, w, h, 32, w * 4, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
     1.8 +            surf = SDL_CreateRGBSurface(0, w, h, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
     1.9 +            if (surf != NULL) {
    1.10 +                memcpy(surf->pixels, data, w * h * 4);
    1.11 +            }
    1.12              free(data);
    1.13  
    1.14              if(freesrc)
    1.15                  SDL_RWclose(src);
    1.16  
    1.17 +            /* If SDL_CreateRGBSurface returns NULL, it has set the error message for us */
    1.18              return surf;
    1.19          }
    1.20      }