diff --git a/includes/Cub3D.h b/includes/Cub3D.h index c305489..6854669 100644 --- a/includes/Cub3D.h +++ b/includes/Cub3D.h @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/13 16:30:59 by apommier #+# #+# */ -/* Updated: 2022/06/15 15:51:37 by apommier ### ########.fr */ +/* Updated: 2022/06/15 17:02:52 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,6 +88,7 @@ typedef struct need_to_be_free char **tab; char **tab_two; unsigned char *str; + char *string; int fd; } to_free; diff --git a/libft/get_next_line.c b/libft/get_next_line.c index 24ca95c..5ae7ec3 100644 --- a/libft/get_next_line.c +++ b/libft/get_next_line.c @@ -14,13 +14,16 @@ char *ft_free(char *save, int *end) { - if (!*end) + if (!end || !*end) { - free(save); - free(end); + if (save) + free(save); + if (end) + free(end); return (0); } - free(end); + if (end) + free(end); return (save); } @@ -81,7 +84,10 @@ char *get_next_line(int fd) line = 0; if (fd < 0) + { + ft_free(save, 0); return (0); + } end = malloc(sizeof(int *)); *end = 1; if (save == NULL) diff --git a/srcs/get_texture_array.c b/srcs/get_texture_array.c index a13a3ad..5b8eb1b 100644 --- a/srcs/get_texture_array.c +++ b/srcs/get_texture_array.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/06 16:10:11 by apommier #+# #+# */ -/* Updated: 2022/06/15 16:12:02 by apommier ### ########.fr */ +/* Updated: 2022/06/15 17:25:21 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,7 +85,7 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list close(fd); img->to_be_free.fd = -1; if (count != 12291) - ft_exit("Error\nBad texture file\n", img); + ft_exit("Error\nBad texture file (too much line)\n", img); ret = ft_calloc(sizeof(char), count); if (!ret) quit_game(img); @@ -100,7 +100,6 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list if (swap) free(swap); swap = get_next_line(fd); - //printf("str = -%s-\n", swap); if (!count) { free(swap); @@ -112,8 +111,9 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list ret[count] = (unsigned char)ft_atoi(swap); else if (swap) { + get_next_line(-1); free(swap); - ft_exit("Error\nBad texture file2\n", img); + ft_exit("Error\nBad texture file (not numbers or to high)\n", img); } count++; } diff --git a/srcs/main.c b/srcs/main.c index 0861ab6..42c5549 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/13 16:42:55 by apommier #+# #+# */ -/* Updated: 2022/06/15 15:52:45 by apommier ### ########.fr */ +/* Updated: 2022/06/15 17:16:33 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,6 +108,5 @@ int main(int argc, char **argv) mlx_hook(img.mlx_win, 3, 1L << 1, key_released, &img); mlx_loop_hook(img.mlx, loop, &img); mlx_hook(img.mlx_win, 17, 0L, &quit_game, &img); - mlx_loop(img.mlx); } diff --git a/srcs/parsing/check_color_texture.c b/srcs/parsing/check_color_texture.c index 743b68d..b0864c8 100644 --- a/srcs/parsing/check_color_texture.c +++ b/srcs/parsing/check_color_texture.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/11 01:00:17 by apommier #+# #+# */ -/* Updated: 2022/06/15 15:49:19 by apommier ### ########.fr */ +/* Updated: 2022/06/15 17:24:06 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,13 +26,6 @@ int next_space_index(char *str, int i) return (i); } -/*char next_line_space(char **tab, int i) -{ - while (!next_space(tab[i], 0)) - i++; - return (tab[i]); -}*/ - char *transform_map(char **double_map, t_data *img) { char *map; @@ -42,9 +35,7 @@ char *transform_map(char **double_map, t_data *img) i = -1; index = 0; - //print_double_fd(double_map, 1); img->map.size = img->map.x * img->map.y; - //printf("x= %d y= %d\n", img->map.x, img->map.y); map = ft_calloc(sizeof(char), img->map.size + 1); if (!map) quit_game(img); @@ -53,17 +44,11 @@ char *transform_map(char **double_map, t_data *img) j = -1; while (double_map[i][++j]) { - //printf("INDEX= %d\n", i * img->map.x + j); - //if () map[i * img->map.x + j] = double_map[i][j]; - //map[index] = double_map[i][j]; - //printf("index= %d\n", index); index++; } - } img->map.simple_map = map; - //printf("map = -%s-\n", map); return (0); } @@ -92,7 +77,6 @@ void set_texture_file(char *str, t_data *img, char c) if (str[index + 1] != 'A' || str[index + 2] != ' ') ft_exit("Error\nBad syntax in map file\n", img); } - //printf("path= -%s-\n", str + index + 3); get_texture(c, str + index + 3, img); } @@ -128,8 +112,6 @@ void set_color_utils(char **tab, color *rgb, t_data *img) rgb->g = (unsigned char)ft_atoi(tab[1]); rgb->b = (unsigned char)ft_atoi(tab[2]); rgb->set = 1; - //printf("---%d\n", img->g); - } void set_color(char *str, t_data *img) @@ -144,16 +126,12 @@ void set_color(char *str, t_data *img) if (str[index] == ',' && str[index + 1] == ',') ft_exit("Error\nBad syntax for RGB identifier\n", img); } - //printf("str=%s \n", str); c = next_space(str, 0); index = next_space_index(str + 1, 0); tab = ft_split(str + index + 1, ','); if (!tab) quit_game(img); img->to_be_free.tab_two = tab; - //if (double_size(tab) != 3) - // ft_exit("Error\nBad syntax in map file (RGB) 1\n"); - //print_double_fd(tab, 1); if (c == 'F') set_color_utils(tab, &img->map.floor, img); if (c == 'C') @@ -166,13 +144,9 @@ int check_texture_color(char **tab, t_data *img) { int next; int index; - //char line; index = 0; next = 0; - //int i = 0; - //while (tab[i]) - // printf("%s\n", tab[i++]); while (next_space(tab[next], 0) != '1' && tab[next]) next++; if (!tab[next]) @@ -182,10 +156,7 @@ int check_texture_color(char **tab, t_data *img) if (next_space(tab[index], 0) == 'N' || next_space(tab[index], 0) == 'S' || next_space(tab[index], 0) == 'W' || next_space(tab[index], 0) == 'E') set_texture_file(tab[index], img, next_space(tab[index], 0)); else if (next_space(tab[index], 0) == 'F' || next_space(tab[index], 0) == 'C') - { set_color(tab[index], img); - - } else if (next_space(tab[index], 0)) ft_exit("Error\nBad syntax in map file (identifier)\n", img); index++;