From ca5fa86d1039c7c97519597157e4f5a90bb16417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Thu, 31 Jul 2025 11:55:41 +0200 Subject: [PATCH] fix: prevent zero-division in rare cases --- src/raycast/ray.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/raycast/ray.c b/src/raycast/ray.c index 6cbd601..0bcb866 100644 --- a/src/raycast/ray.c +++ b/src/raycast/ray.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ray.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: tchampio +#+ +:+ +#+ */ +/* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/07/30 12:10:17 by tchampio #+# #+# */ -/* Updated: 2025/07/30 16:06:19 by tchampio ### ########.fr */ +/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */ +/* Updated: 2025/07/31 11:58:02 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ #include "../player/player.h" #include "../consts.h" #include "../cub3d_data.h" +#include #include void init_ray(t_ray *ray, int pos_x, t_player *player) @@ -79,6 +80,8 @@ void calculate_wall_dist(t_ray *ray, char **map) void calculate_wall_height(t_ray *ray, t_player *player) { + if (ray->wall_dist <= FLT_EPSILON) + ray->wall_dist = 0.1; ray->wall_height = (int)(HEIGHT / ray->wall_dist); ray->draw_start = -ray->wall_height / 2 + HEIGHT / 2; if (ray->draw_start < 0)