From d193b99c568f0bf56b8b4361956546d3ebea5101 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 15:31:18 +0100 Subject: [PATCH] fixed leak --- algo.c | 4 ++-- algo.h | 5 +++-- utils.c | 17 +++++++++++++++-- utils.h | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/algo.c b/algo.c index 2d2eef2..a157ed8 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 14:33:28 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 15:28:25 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; -// t_tex g_tex; // TODO manage image format error better @@ -57,6 +56,7 @@ void draw_screen(void) render(img_data, &tex); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); + clean_img(&tex); } static void loop(void) diff --git a/algo.h b/algo.h index 32839ac..22561c4 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:27:27 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 15:29:30 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,6 @@ extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; -// extern t_tex g_tex; /// @brief Write an error message on stderr. /// @@ -86,4 +85,6 @@ void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, int y, u_int32_t *img_data); + +void clean_img(t_tex *tex); #endif diff --git a/utils.c b/utils.c index e265cdf..fd4555e 100644 --- a/utils.c +++ b/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:36:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 15:28:56 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,3 +69,16 @@ void timedloop(void (*f)(void)) f(); ticks++; } + +void clean_img(t_tex *tex) +{ + int i; + + i = 0; + while (i <= 3) + { + if (tex->textures[i]) + mlx_destroy_image(g_mlx, tex->textures[i]); + i++; + } +} \ No newline at end of file diff --git a/utils.h b/utils.h index 93a619d..bb83116 100644 --- a/utils.h +++ b/utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:41:09 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 15:27:17 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */