From a46fdff49a08b400a098f6f72491233b7da3882c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 5 Aug 2025 15:10:12 +0200 Subject: [PATCH] fix: correct error exit code when texture has error --- src/utils/frees.c | 4 ++-- src/utils/frees.h | 2 +- src/utils/hooks.c | 2 +- src/utils/inits.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/frees.c b/src/utils/frees.c index 6319134..8cb62ca 100644 --- a/src/utils/frees.c +++ b/src/utils/frees.c @@ -58,7 +58,7 @@ void free_map(t_mapdata *map) free(map); } -int destroy(t_cub3d_data *data) +int destroy(t_cub3d_data *data, int exit_code) { free_map(data->map); if (data->mlx_win) @@ -82,7 +82,7 @@ int destroy(t_cub3d_data *data) mlx_destroy_display(data->mlx); free(data->mlx); free(data->screen_matrix); - exit(0); + exit(exit_code); return (0); } diff --git a/src/utils/frees.h b/src/utils/frees.h index 0b3813f..2968aa8 100644 --- a/src/utils/frees.h +++ b/src/utils/frees.h @@ -16,7 +16,7 @@ # include "../cub3d_data.h" void gnl_exhaust(int fd); -int destroy(t_cub3d_data *data); +int destroy(t_cub3d_data *data, int exit_code); void free_tab(char **tab); void free_tab_length(char **tab, int length); void free_map(t_mapdata *map); diff --git a/src/utils/hooks.c b/src/utils/hooks.c index 9ec9356..17918c8 100644 --- a/src/utils/hooks.c +++ b/src/utils/hooks.c @@ -22,7 +22,7 @@ int keypress_handler(int keycode, t_cub3d_data *data) { if (keycode == XK_Escape) - destroy(data); + destroy(data, 0); if (keycode == XK_w) data->keypresses.is_w_pressed = true; if (keycode == XK_a) diff --git a/src/utils/inits.c b/src/utils/inits.c index 202fc5d..0447da4 100644 --- a/src/utils/inits.c +++ b/src/utils/inits.c @@ -28,12 +28,12 @@ t_img_data *load_single_texture(t_cub3d_data *data, char *path) if (img == NULL) { ft_printf("Error: failed to open image at %s\n", path); - destroy(data); + destroy(data, 1); } if (width != height || width != TEXTURE_SIZE) { ft_printf("Error: textures are not the right size\n"); - destroy(data); + destroy(data, 1); } ft_printf("image: %p\n", img); img_data = ft_calloc(sizeof(t_img_data), 1);