aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_exit.c4
-rw-r--r--src/ft_init_lists.c2
-rw-r--r--src/ft_init_s_ray.c2
-rw-r--r--src/ft_raycasting.c14
-rw-r--r--src/ft_save_to_bmp.c7
-rw-r--r--src/ft_warp_level.c9
6 files changed, 24 insertions, 14 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 97c9e02..fb6de09 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -57,6 +57,10 @@ static void
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);
+ if (clist->mlist.isftex && clist->tlist[6].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img);
+ if (clist->mlist.isctex && clist->tlist[7].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img);
}
int
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index bd2ae74..82f5c0e 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -76,6 +76,8 @@ static int8_t
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
+ if (!(cl->rlist.wall_dist_tab = (float*)malloc(1 * sizeof(float))))
+ return (-1);
cl->currlvl = 0;
cl->walltexgood = 0;
ft_init_funptr(cl);
diff --git a/src/ft_init_s_ray.c b/src/ft_init_s_ray.c
index e890d68..0d4ba96 100644
--- a/src/ft_init_s_ray.c
+++ b/src/ft_init_s_ray.c
@@ -11,6 +11,8 @@
/* ************************************************************************** */
#include <cub3d.h>
+#include <stdlib.h>
+#include <stddef.h>
t_ray
ft_init_s_ray(void)
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 3cbd368..baa71af 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -83,17 +83,16 @@ static void
void
ft_castray(t_cub *cl)
{
- uint16_t i;
- t_win *wl;
- float *dist_tab;
+ uint16_t i;
+ t_win *wl;
+ ft_memdel((void**)&cl->rlist.wall_dist_tab);
wl = &cl->wlist;
i = (wl->y_size / 2) + 1;
while (++i < wl->y_size)
ft_floor_cast(i, cl);
- if (!(dist_tab = malloc(sizeof(float) * cl->wlist.x_size)))
- return ;
- if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist.x_size)))
+ if (!(cl->rlist.wall_dist_tab =
+ (float*)malloc(sizeof(float) * cl->wlist.x_size)))
return ;
i = 0;
while (i < wl->x_size)
@@ -102,8 +101,7 @@ void
ft_choose_tex(cl);
ft_calc_tex(cl);
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
- dist_tab[i] = cl->rlist.wall_dist;
- cl->rlist.wall_dist_tab = dist_tab;
+ cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
i++;
}
}
diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c
index 90bbb1f..ae3a2b6 100644
--- a/src/ft_save_to_bmp.c
+++ b/src/ft_save_to_bmp.c
@@ -93,9 +93,10 @@ static int8_t
bmp_info.size_image = size;
if (!(fd = open(fname, O_RDWR | O_CREAT, 0644)))
return (-1);
- write(fd, &bmp_file, sizeof(t_bmp_file));
- write(fd, &bmp_info, sizeof(t_bmp_info));
- write(fd, bmp, size);
+ if (!write(fd, &bmp_file, sizeof(t_bmp_file)) ||
+ !write(fd, &bmp_info, sizeof(t_bmp_info)) ||
+ !write(fd, bmp, size))
+ return (-1);
close(fd);
return (0);
}
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 4a02c2b..1f744c2 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -59,13 +59,16 @@ static void
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
- i = 0;
- while (i <= 5)
+ i = -1;
+ while (++i <= 5)
{
mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img);
cl->tlist[i].img = NULL;
- i++;
}
+ if (cl->mlist.isftex && cl->tlist[6].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img);
+ if (cl->mlist.isctex && cl->tlist[7].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img);
}
static void