add null initialisation of mlx pointers and move mb init closer to begining
This commit is contained in:
@@ -5,8 +5,20 @@ void destroy_mlx(void *param)
|
||||
t_game *game;
|
||||
|
||||
game = param;
|
||||
mlx_destroy_image(game->mlx_ptr, game->img.ptr);
|
||||
mlx_destroy_window(game->mlx_ptr, game->win.ptr);
|
||||
if (game->mlx_ptr == NULL)
|
||||
return ;
|
||||
if (game->img.ptr)
|
||||
mlx_destroy_image(game->mlx_ptr, game->img.ptr);
|
||||
if (game->txt.img_n.ptr)
|
||||
mlx_destroy_image(game->mlx_ptr, game->txt.img_n.ptr);
|
||||
if (game->txt.img_s.ptr)
|
||||
mlx_destroy_image(game->mlx_ptr, game->txt.img_s.ptr);
|
||||
if (game->txt.img_e.ptr)
|
||||
mlx_destroy_image(game->mlx_ptr, game->txt.img_e.ptr);
|
||||
if (game->txt.img_w.ptr)
|
||||
mlx_destroy_image(game->mlx_ptr, game->txt.img_w.ptr);
|
||||
if (game->win.ptr)
|
||||
mlx_destroy_window(game->mlx_ptr, game->win.ptr);
|
||||
mlx_destroy_display(game->mlx_ptr);
|
||||
}
|
||||
|
||||
@@ -24,19 +36,15 @@ int main(int ac, char **av)
|
||||
write(2, "Error\nPlease use a valid .cub file as single argument.\n", 53))
|
||||
return (EXIT_FAILURE);
|
||||
game = init_struct();
|
||||
mb_init(destroy_mlx, game);
|
||||
if (init_parsing(game, av[1]) && write(2, "The .cub file is invalid.\n", 26))
|
||||
return (EXIT_FAILURE);
|
||||
if (check_map(&(game->map)) && write(2, "The map is invalid.\n", 20))
|
||||
return (EXIT_FAILURE);
|
||||
|
||||
// init game variables
|
||||
init_game(game);
|
||||
|
||||
mb_init(destroy_mlx, game);
|
||||
|
||||
// draw game a first time before it start
|
||||
draw(game);
|
||||
|
||||
// receive a keypress event
|
||||
mlx_hook(game->win.ptr, 2, 1L << 0, keypress, game);
|
||||
// receive a keyprelease event
|
||||
|
||||
Reference in New Issue
Block a user