diff --git a/Makefile b/Makefile index 0678d5e..ebdf9d1 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ CC=cc -SANITIZERS=-fsanitize=address -fno-omit-frame-pointer +SANITIZERS= +#-fsanitize=address -fno-omit-frame-pointer CFLAGS=-Wall -Wextra -Werror -ggdb $(SANITIZERS) -I mlx SOURCEFILES=src/main.c \ src/map/map_checker.c \ src/map/checkers.c \ - src/map/setters.c + src/map/setters.c \ + src/utils/frees.c OBJECTS=$(patsubst src/%.c,objects/%.o,$(SOURCEFILES)) OBJDIR=objects NAME=cub3d diff --git a/includes/maputils.h b/includes/maputils.h index b7745e3..4e5ecd7 100644 --- a/includes/maputils.h +++ b/includes/maputils.h @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:34:43 by tchampio #+# #+# */ -/* Updated: 2025/06/21 19:47:07 by tchampio ### ########.fr */ +/* Updated: 2025/06/25 17:57:24 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,5 +43,6 @@ int copy_old_map(t_mapdata *map, char **newmap, void add_map_line(const char *line, t_mapdata *map); void print_map(char **map); bool check_cubfile(char *file, t_mapdata *map); +void free_map(t_mapdata *map); #endif diff --git a/includes/structs.h b/includes/structs.h index e933ffd..4145950 100644 --- a/includes/structs.h +++ b/includes/structs.h @@ -6,13 +6,15 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:46:20 by tchampio #+# #+# */ -/* Updated: 2025/06/24 11:47:02 by tchampio ### ########.fr */ +/* Updated: 2025/06/25 17:52:35 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef STRUCTS_H # define STRUCTS_H +# include + typedef struct s_mlx_data { void *img; diff --git a/objects/utils/.gitkeep b/objects/utils/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c index 4348fe0..f24d6e5 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: tchampio map); - free_tab(map->mapflood); - free(map->ea_texture); - free(map->no_texture); - free(map->so_texture); - free(map->we_texture); - free(map->filename); + free_map(data->map); + if (data->mlx_win) + mlx_destroy_window(data->mlx, data->mlx_win); + if (data->mlx_data) + mlx_destroy_image(data->mlx, data->mlx_data->img); + free(data->mlx_data); + if (data->mlx) + mlx_destroy_display(data->mlx); + free(data->mlx); exit(0); return 0; } -int key_destroy(int keycode, t_mapdata *map) +int key_destroy(int keycode, t_cub3d_data *data) { if (keycode == 65307) - destroy(map); + destroy(data); return (0); } @@ -111,11 +99,12 @@ int main(int argc, char **argv) return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1); data.mlx = mlx_init(); data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d"); + data.mlx_data = ft_calloc(sizeof(t_mlx_data), 1); data.mlx_data->img = mlx_new_image(data.mlx, 800, 600); data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian); - mlx_hook(data.mlx_win, 17, 0L, destroy, data.map); + mlx_hook(data.mlx_win, 17, 0L, destroy, &data); draw_map(data.map, data.mlx_data); - mlx_key_hook(data.mlx_win, key_destroy, data.map); + mlx_key_hook(data.mlx_win, key_destroy, &data); mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0); mlx_loop(data.mlx); } diff --git a/src/utils/frees.c b/src/utils/frees.c new file mode 100644 index 0000000..9480722 --- /dev/null +++ b/src/utils/frees.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* frees.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio + +void free_tab(char **tab) +{ + int i; + + if (!tab) + return ; + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); +} + +void free_map(t_mapdata *map) +{ + free_tab(map->map); + free_tab(map->mapflood); + free(map->ea_texture); + free(map->no_texture); + free(map->so_texture); + free(map->we_texture); + free(map->filename); + free(map); +} diff --git a/vgcore.124879 b/vgcore.124879 new file mode 100644 index 0000000..7fd5efe Binary files /dev/null and b/vgcore.124879 differ diff --git a/vgcore.127690 b/vgcore.127690 new file mode 100644 index 0000000..3580aea Binary files /dev/null and b/vgcore.127690 differ diff --git a/vgcore.142306 b/vgcore.142306 new file mode 100644 index 0000000..535944b Binary files /dev/null and b/vgcore.142306 differ diff --git a/vgcore.142888 b/vgcore.142888 new file mode 100644 index 0000000..891088e Binary files /dev/null and b/vgcore.142888 differ