feat: close window and exit on window close event

This commit is contained in:
Khaïs COLIN 2025-08-20 13:51:23 +02:00
parent 0771881690
commit fb4680e4bd
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/08/18 20:05:29 by tchampio ### ########.fr */
/* Updated: 2025/08/20 13:52:42 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@
#include "raycast/ray.h"
#include "sprites/sprite_caster.h"
#include "utils/inits.h"
#include "sprites/sprite.h"
#include "utils/frees.h"
#include "utils/hooks.h"
#include "utils/inits.h"
#include <bits/types/struct_timeval.h>
@ -59,6 +59,12 @@ int game_loop(t_cub3d_data *data)
return (0);
}
int good_bye(void *data)
{
destroy(data, 0);
return (0);
}
int main(int argc, char **argv)
{
t_cub3d_data data;
@ -72,6 +78,7 @@ int main(int argc, char **argv)
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
keyrelease_handler, &data);
mlx_hook(data.mlx_win, DestroyNotify, NoEventMask, good_bye, &data);
mlx_loop_hook(data.mlx, game_loop, &data);
mlx_loop(data.mlx);
}