From 1eaee0bbea20c2dfea647d083e02978838e00ca1 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 8 Jan 2014 14:38:42 +0100 Subject: [PATCH] (PS3) Overlays work now - properly mallocs image size now --- ps3/image.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ps3/image.c b/ps3/image.c index a902b8acb7..6b743fb083 100644 --- a/ps3/image.c +++ b/ps3/image.c @@ -79,6 +79,7 @@ static int img_free(void *ptr, void *a) static bool ps3graphics_load_jpeg(const char *path, struct texture_image *out_img) { + size_t img_size; #ifndef __PSL1GHT__ CtrlMallocArg MallocArg; CtrlFreeArg FreeArg; @@ -153,6 +154,10 @@ static bool ps3graphics_load_jpeg(const char *path, struct texture_image *out_im if (ret != CELL_OK) goto error; + img_size = outParam.output_width * outParam.output_height * sizeof(uint32_t); + out_img->pixels = (uint32_t*)malloc(img_size); + memset(out_img->pixels, 0, img_size); + #ifdef __PSL1GHT__ uint64_t output_bytes_per_line = outParam.output_width * 4; ret = cellJpgDecDecodeData(mHandle, sHandle, (uint8_t*)out_img->pixels, &output_bytes_per_line, &dOutInfo); @@ -174,6 +179,9 @@ static bool ps3graphics_load_jpeg(const char *path, struct texture_image *out_im error: RARCH_ERR("ps3graphics_load_jpeg(): error.\n"); + if (out_img->pixels) + free(out_img->pixels); + out_img->pixels = 0; if (mHandle && sHandle) cellJpgDecClose(mHandle, sHandle); if (mHandle) @@ -187,6 +195,7 @@ error: static bool ps3graphics_load_png(const char *path, struct texture_image *out_img) { + size_t img_size; #ifndef __PSL1GHT__ CtrlMallocArg MallocArg; CtrlFreeArg FreeArg; @@ -261,6 +270,10 @@ static bool ps3graphics_load_png(const char *path, struct texture_image *out_img if (ret != CELL_OK) goto error; + img_size = outParam.output_width * outParam.output_height * sizeof(uint32_t); + out_img->pixels = (uint32_t*)malloc(img_size); + memset(out_img->pixels, 0, img_size); + #ifdef __PSL1GHT__ uint64_t output_bytes_per_line = outParam.output_width * 4; ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)out_img->pixels, &output_bytes_per_line, &dOutInfo); @@ -283,6 +296,9 @@ static bool ps3graphics_load_png(const char *path, struct texture_image *out_img error: RARCH_ERR("ps3graphics_load_png(): error.\n"); + if (out_img->pixels) + free(out_img->pixels); + out_img->pixels = 0; if (mHandle && sHandle) cellPngDecClose(mHandle, sHandle); if (mHandle) @@ -293,23 +309,15 @@ error: bool texture_image_load(const char *path, struct texture_image *out_img) { - size_t size = out_img->width * out_img->height * sizeof(uint32_t); - out_img->pixels = (uint32_t*)malloc(size); if(strstr(path, ".PNG") != NULL || strstr(path, ".png") != NULL) { if (!ps3graphics_load_png(path, out_img)) - { - texture_image_free(out_img); return false; - } } else { if (!ps3graphics_load_jpeg(path, out_img)) - { - texture_image_free(out_img); return false; - } } return true; @@ -317,6 +325,7 @@ bool texture_image_load(const char *path, struct texture_image *out_img) void texture_image_free(struct texture_image *img) { - free(img->pixels); + if (img->pixels) + free(img->pixels); memset(img, 0, sizeof(*img)); }