diff --git a/check.c b/check.c index d2aa294..cb74ddf 100644 --- a/check.c +++ b/check.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/14 18:28:42 by yantoine #+# #+# */ -/* Updated: 2025/02/25 01:44:31 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 16:18:05 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,3 +24,20 @@ int check_if_max(t_scene scene, const int to_test, const int max) return (0); return (1); } + +int check_nb_element(t_scene scene) +{ + if (scene.num_spheres > MAX_SPHERES) + return (0); + if (scene.num_planes > MAX_PLANES) + return (0); + if (scene.num_cylinders > MAX_CYLINDERS) + return (0); + if (scene.num_lights > MAX_LIGHTS) + return (0); + if (scene.num_ambient > MAX_AMBIENT) + return (0); + if (scene.num_camera > MAX_CAMERA) + return (0); + return (1); +} diff --git a/config.c b/config.c index 22ef56f..2bc511a 100644 --- a/config.c +++ b/config.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/14 01:41:17 by yantoine #+# #+# */ -/* Updated: 2025/03/05 14:53:12 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 16:27:44 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,8 +85,12 @@ t_scene load_config(const char *filename) line = scene.all_file[i]; if (!line) break ; + if (!check_nb_element(scene)) + { + ft_free_array(scene.all_file); + exit(1); + } scene = parsing_line(line, scene); - } ft_free_array(scene.all_file); return (scene); diff --git a/miniRT.h b/miniRT.h index 802803e..13f40c9 100644 --- a/miniRT.h +++ b/miniRT.h @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */ -/* Updated: 2025/03/05 14:29:14 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 16:05:28 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -241,6 +241,7 @@ int check_tokens(char **tokens, int expected); int isdigit_token(char **tokens); int have_extension(const char *line); int check_if_max(t_scene scene, const int to_test, const int max); +int check_nb_element(t_scene scene); // Intersection float intersect_cylinder(t_ray ray, t_cylinder cy, t_vec3 *hitNormal);