aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_exit.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_exit.c69
1 files changed, 47 insertions, 22 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index b9e061f..659d0ec 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -15,38 +15,63 @@
#include <mlx.h>
#include <stddef.h>
#include <stdlib.h>
-#include <inttypes.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <stdint.h>
static void
ft_free_lists(t_cub *clist)
{
- 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->mapl);
- ft_free_words(clist->mlist->map);
- ft_memdel((void**)&clist->mlist);
- ft_memdel((void**)&clist->plist);
- if (!clist->wlist->inited)
- ft_memdel((void**)&clist->wlist->winptr);
- ft_memdel((void**)&clist->wlist->wlx);
- ft_memdel((void**)&clist->wlist);
- ft_memdel((void**)&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.fl_tex_path);
+ ft_memdel((void**)&clist->mlist.ce_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->wlist->inited)
+ 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)
{
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[0].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[1].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[2].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[3].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[4].img);
- mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr);
+ kill(clist->mpid, SIGTERM);
+ wait(&clist->mpid);
}
ft_free_lists(clist);
ft_printf("Exiting program\n");