aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-11 09:50:36 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-11 09:50:36 +0100
commitbfa1f4e6e61152ba3ff555d1508f43f0a5ab2754 (patch)
tree4eaa82a01e2e9ce65be74365233d8ec9fbcce253 /src
parentGood trap init (diff)
download42-cub3d-bfa1f4e6e61152ba3ff555d1508f43f0a5ab2754.tar.gz
42-cub3d-bfa1f4e6e61152ba3ff555d1508f43f0a5ab2754.tar.bz2
42-cub3d-bfa1f4e6e61152ba3ff555d1508f43f0a5ab2754.tar.xz
42-cub3d-bfa1f4e6e61152ba3ff555d1508f43f0a5ab2754.tar.zst
42-cub3d-bfa1f4e6e61152ba3ff555d1508f43f0a5ab2754.zip
Secured collision segv
Diffstat (limited to 'src')
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_init_lists.c2
-rw-r--r--src/ft_key_loop.c13
-rw-r--r--src/ft_warp_level.c17
4 files changed, 15 insertions, 19 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 3b00701..4125567 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -62,6 +62,8 @@ static void
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);
+ if (clist->mlist.istrap && clist->tlist[15].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img);
}
int
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index bd2ae74..8ba9a13 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -28,7 +28,7 @@ t_rgb
return (rgb);
}
-static t_player
+t_player
ft_init_player(void)
{
t_player plist;
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index d3e871b..c68b228 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -26,7 +26,7 @@ static uint64_t
return (pl->pos_x - (pl->dir_y * FT_COLL_MULT));
else if (key == 3)
return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2)));
- return (1);
+ return ((uint64_t)pl->pos_x);
}
static uint64_t
@@ -40,9 +40,10 @@ static uint64_t
return (pl->pos_y - (pl->dir_x * FT_COLL_MULT));
else if (key == 3)
return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2)));
- return (1);
+ return ((uint64_t)pl->pos_y);
}
+#include <stdio.h>
static void
ft_collision(float old_y, float old_x, int32_t key, t_cub *cl)
{
@@ -75,8 +76,12 @@ int
ft_collision(old_y, old_x, cl->key_input[i], cl);
if (cl->mlist.isnlvl)
{
- if (ft_warp_level(cl) < 0)
- return (ft_exit(FT_RET_FAILED_STRUCTS, cl));
+ if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
+ (uint32_t)cl->plist.pos_y == cl->mlist.nly)
+ {
+ return ((ft_warp_level(cl) < 0) ?
+ (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0));
+ }
}
i++;
}
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 3c9110f..a4f705b 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -47,16 +47,7 @@ static void
{
uint8_t i;
- cl->plist.pos_x = 0;
- cl->plist.pos_y = 0;
- cl->plist.pos_z = 0;
- cl->plist.start_x = 0;
- cl->plist.start_y = 0;
- cl->plist.cam_x = 0;
- cl->plist.dir_x = -1;
- cl->plist.dir_y = 0;
- cl->plist.plane_x = 0;
- cl->plist.plane_y = 0.66;
+ cl->plist = ft_init_player();
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
@@ -70,6 +61,8 @@ static void
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);
+ if (cl->mlist.istrap && cl->tlist[15].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img);
}
static void
@@ -100,9 +93,6 @@ int8_t
char *tmp_mup;
uint8_t isoldmus;
- if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
- (uint32_t)cl->plist.pos_y == cl->mlist.nly)
- {
if (!(next_path = (char *)malloc((ft_strlen(
cl->mlist.nlevel_path) + 1) * sizeof(char))))
return (-1);
@@ -119,6 +109,5 @@ int8_t
ft_memdel((void**)&tmp_mup);
ft_wall_tex_init(cl);
ft_memdel((void**)&next_path);
- }
return (0);
}