fix: fixed textures leaks

This commit is contained in:
Theo Champion 2025-09-08 17:11:58 +02:00
parent 80150ce24d
commit f407f5b7ce
3 changed files with 41 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:05:31 by kcolin ### ########.fr */
/* Updated: 2025/09/08 17:02:43 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,15 @@
#include "../../mlx/mlx.h"
#include <stdlib.h>
void destroy_texture(t_cub3d_data *data, t_img_data *data_img)
{
if (data)
{
mlx_destroy_image(data->mlx, data_img->img);
}
free(data_img);
}
void destroy_textures(t_cub3d_data *data)
{
if (data->no_texture)
@ -45,3 +54,30 @@ void destroy_sprites(t_cub3d_data *data)
sprite++;
}
}
void destroy_hud_textures(t_cub3d_data *data)
{
int i;
i = 0;
while (i < 10)
{
destroy_texture(data, data->point_figures[i++]);
}
i = 0;
while (i < 10)
{
destroy_texture(data, data->round_figures[i++]);
}
i = 0;
while (i < 5)
{
destroy_texture(data, data->tally_marks[i++]);
}
i = 0;
while (i < 3)
{
destroy_texture(data, data->perk_logos[i++]);
}
destroy_texture(data, data->gun);
}

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/11 12:07:48 by tchampio #+# #+# */
/* Updated: 2025/08/11 12:10:21 by tchampio ### ########.fr */
/* Updated: 2025/09/08 14:15:25 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,5 +17,6 @@
void destroy_textures(t_cub3d_data *data);
void destroy_sprites(t_cub3d_data *data);
void destroy_hud_textures(t_cub3d_data *data);
#endif

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */
/* Updated: 2025/08/12 15:38:45 by tchampio ### ########.fr */
/* Updated: 2025/09/08 14:15:58 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -67,6 +67,7 @@ int destroy(t_cub3d_data *data, int exit_code)
if (data->img_data)
mlx_destroy_image(data->mlx, data->img_data->img);
destroy_textures(data);
destroy_hud_textures(data);
destroy_sprites(data);
free(data->img_data);
if (data->mlx)