aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_loop.c
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/ft_key_loop.c
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/ft_key_loop.c')
-rw-r--r--src/ft_key_loop.c13
1 files changed, 9 insertions, 4 deletions
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++;
}