From a8c15fdef474364d13273fceeb03b007c3f09a4d Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Mon, 10 Jun 2019 16:42:52 -0700 Subject: [PATCH] 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/IMG.c b/IMG.c index c6f0a020..a213f9e6 100644 --- a/IMG.c +++ b/IMG.c @@ -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; } }