Skip to content

Commit

Permalink
Copy the pixel data into the surface
Browse files Browse the repository at this point in the history
It was getting immediately freed out from underneath the surface, SDL_CreateRGBSurfaceFrom does not copy the pixel data.
  • Loading branch information
codekitchen committed Jun 10, 2019
1 parent aca5bb7 commit a8c15fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion IMG.c
Expand Up @@ -192,12 +192,16 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type)

if(data)
{
surf = SDL_CreateRGBSurfaceFrom(data, w, h, 32, w * 4, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
surf = SDL_CreateRGBSurface(0, w, h, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
if (surf != NULL) {
memcpy(surf->pixels, data, w * h * 4);
}
free(data);

if(freesrc)
SDL_RWclose(src);

/* If SDL_CreateRGBSurface returns NULL, it has set the error message for us */
return surf;
}
}
Expand Down

0 comments on commit a8c15fd

Please sign in to comment.