fix: check that mlx initialized succesfully before using

https://www.notion.so/Segfault-when-DISPLAY-is-invalid-233551de06f480b28d8ec14cd4b23d47?source=copy_link
This commit is contained in:
Khaïs COLIN 2025-07-21 11:29:36 +02:00
parent 8259ef238d
commit c5f15dbf11
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 7 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 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 "map/map_checker.h"
#include "draw/draw_map.h" #include "draw/draw_map.h"
#include "utils/hooks.h" #include "utils/hooks.h"
#include "utils/frees.h"
#include <stdbool.h> #include <stdbool.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/X.h> #include <X11/X.h>
@ -53,6 +54,9 @@ int main(int argc, char **argv)
return (ft_printf("Error: Wrong map file. Reason: %s\n", return (ft_printf("Error: Wrong map file. Reason: %s\n",
data.map->error), 1); data.map->error), 1);
data.mlx = mlx_init(); 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.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d");
data.img_data = ft_calloc(sizeof(t_img_data), 1); data.img_data = ft_calloc(sizeof(t_img_data), 1);
data.img_data->img = mlx_new_image(data.mlx, 800, 600); data.img_data->img = mlx_new_image(data.mlx, 800, 600);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:27:11 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); int destroy(t_cub3d_data *data);
void free_tab(char **tab); void free_tab(char **tab);
void free_tab_length(char **tab, int length); void free_tab_length(char **tab, int length);
void free_map(t_mapdata *map);
#endif // FREES_H #endif // FREES_H