/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_exit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include #include #include #include #include static void ft_free_lists(t_cub *clist) { ft_memdel((void**)&clist->mlist.filename); ft_memdel((void**)&clist->mlist.no_tex_path); ft_memdel((void**)&clist->mlist.so_tex_path); ft_memdel((void**)&clist->mlist.ea_tex_path); ft_memdel((void**)&clist->mlist.we_tex_path); ft_memdel((void**)&clist->mlist.sprite_path); ft_memdel((void**)&clist->mlist.nl_tex_path); ft_memdel((void**)&clist->mlist.nlevel_path); ft_memdel((void**)&clist->mlist.music_path); ft_memdel((void**)&clist->mlist.music_cmd); ft_memdel((void**)&clist->mlist.mapl); ft_free_words(clist->mlist.map); ft_free_words(clist->mlist.mcmd_words); if (!clist->wlist.inited) ft_memdel((void**)&clist->wlist.winptr); } static void ft_del_tex(t_cub *clist) { if (clist->tlist[0].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[0].img); if (clist->tlist[1].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[1].img); if (clist->tlist[2].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[2].img); if (clist->tlist[3].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[3].img); if (clist->tlist[4].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[4].img); if (clist->mlist.isnlvl && clist->tlist[5].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[5].img); } int ft_exit(uint8_t exit_code, t_cub *clist) { if (clist->walltexgood) ft_del_tex(clist); if (clist->wlist.inited) { mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr); clist->wlist.winptr = NULL; } if (clist->isoldmus && clist->wlist.inited) { kill(clist->mpid, SIGTERM); wait(&clist->mpid); } ft_free_lists(clist); ft_printf("Exiting program\n"); exit(exit_code); return (0); }