diff --git a/frontend/menu/disp/rmenu.c b/frontend/menu/disp/rmenu.c index f7806d143d..3c0031a7d4 100644 --- a/frontend/menu/disp/rmenu.c +++ b/frontend/menu/disp/rmenu.c @@ -423,25 +423,7 @@ static void *rmenu_init(void) static void rmenu_free_assets(void *data) { -#ifdef _XBOX1 - if (menu_texture->vertex_buf) - { - menu_texture->vertex_buf->Release(); - menu_texture->vertex_buf = NULL; - } - if (menu_texture->pixels) - { - menu_texture->pixels->Release(); - menu_texture->pixels = NULL; - } -#else - if (menu_texture->pixels) - { - free(menu_texture->pixels); - menu_texture->pixels = NULL; - } -#endif - + texture_image_free(&menu_texture); menu_texture_inited = false; } diff --git a/gfx/image.c b/gfx/image.c index 25839fb492..54034be8b8 100644 --- a/gfx/image.c +++ b/gfx/image.c @@ -233,3 +233,9 @@ bool texture_image_load(const char *path, struct texture_image *out_img) return texture_image_load_argb_shift(path, out_img, 24, 16, 8, 0); } +void texture_image_free(struct texture_image *img) +{ + free(img->pixels); + memset(img, 0, sizeof(*img)); +} + diff --git a/gfx/image.h b/gfx/image.h index 69a805255e..0f1e8c87aa 100644 --- a/gfx/image.h +++ b/gfx/image.h @@ -39,6 +39,7 @@ struct texture_image }; bool texture_image_load(const char *path, struct texture_image* img); +void texture_image_free(struct texture_image *img); #endif diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 1d26d57ec4..e8bb923603 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -511,8 +511,6 @@ static void load_texture_data(GLuint obj, const struct texture_image *img, bool glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, img->width, img->height, 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img->pixels); - - free(img->pixels); } static bool load_textures(void) @@ -528,7 +526,7 @@ static bool load_textures(void) RARCH_LOG("Loading image from: \"%s\".\n", cg_shader->lut[i].path); - struct texture_image img; + struct texture_image img = {0}; if (!texture_image_load(cg_shader->lut[i].path, &img)) { RARCH_ERR("Failed to load picture ...\n"); @@ -538,6 +536,7 @@ static bool load_textures(void) load_texture_data(lut_textures[i], &img, cg_shader->lut[i].filter != RARCH_FILTER_NEAREST, gl_wrap_type_to_enum(cg_shader->lut[i].wrap)); + texture_image_free(&img); } glBindTexture(GL_TEXTURE_2D, 0); diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 7866ce6fc6..3bae1d2da7 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -324,7 +324,7 @@ static bool load_luts(void) RARCH_GL_FORMAT32, img.pixels); glBindTexture(GL_TEXTURE_2D, 0); - free(img.pixels); + texture_image_free(&img); } return true; diff --git a/input/overlay.c b/input/overlay.c index c7799f4307..86e01f841a 100644 --- a/input/overlay.c +++ b/input/overlay.c @@ -239,10 +239,10 @@ static void input_overlay_free_overlay(struct overlay *overlay) { size_t i; for (i = 0; i < overlay->size; i++) - free(overlay->descs[i].image.pixels); + texture_image_free(&overlay->descs[i].image); free(overlay->load_images); free(overlay->descs); - free(overlay->image.pixels); + texture_image_free(&overlay->image); } static void input_overlay_free_overlays(input_overlay_t *ol) diff --git a/ps3/image.c b/ps3/image.c index a17ed0ba45..52718dbf16 100644 --- a/ps3/image.c +++ b/ps3/image.c @@ -314,3 +314,10 @@ bool texture_image_load(const char *path, struct texture_image *out_img) return true; } + +void texture_image_free(struct texture_image *img) +{ + free(img->pixels); + memset(img, 0, sizeof(*img)); +} + diff --git a/xdk/image.c b/xdk/image.c index ca60daf761..229e1ace6d 100644 --- a/xdk/image.c +++ b/xdk/image.c @@ -53,3 +53,13 @@ bool texture_image_load(const char *path, struct texture_image *out_img) return true; } + +void texture_image_free(struct texture_image *img) +{ + if (img->vertex_buf) + img->vertex_buf->Release(); + if (img->pixels) + img->pixels->Release(); + memset(img, 0, sizeof(*img)); +} +