From c5f15dbf1122ee12658ffa8cff9fb92d5d6bc11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 21 Jul 2025 11:29:36 +0200 Subject: [PATCH] fix: check that mlx initialized succesfully before using https://www.notion.so/Segfault-when-DISPLAY-is-invalid-233551de06f480b28d8ec14cd4b23d47?source=copy_link --- src/main.c | 6 +++++- src/utils/frees.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 11f157b..9c60184 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ -/* Updated: 2025/07/17 15:52:57 by kcolin ### ########.fr */ +/* Updated: 2025/07/21 11:42:12 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ #include "map/map_checker.h" #include "draw/draw_map.h" #include "utils/hooks.h" +#include "utils/frees.h" #include #include #include @@ -53,6 +54,9 @@ int main(int argc, char **argv) return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1); data.mlx = mlx_init(); + if (data.mlx == NULL) + return (ft_printf("Error: Failed to initalize mlx\n"), + free_map(data.map), 1); data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d"); data.img_data = ft_calloc(sizeof(t_img_data), 1); data.img_data->img = mlx_new_image(data.mlx, 800, 600); diff --git a/src/utils/frees.h b/src/utils/frees.h index 0b596bb..0b3813f 100644 --- a/src/utils/frees.h +++ b/src/utils/frees.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:27:11 by kcolin #+# #+# */ -/* Updated: 2025/07/17 15:54:20 by kcolin ### ########.fr */ +/* Updated: 2025/07/21 11:36:53 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,5 +19,6 @@ void gnl_exhaust(int fd); int destroy(t_cub3d_data *data); void free_tab(char **tab); void free_tab_length(char **tab, int length); +void free_map(t_mapdata *map); #endif // FREES_H