Fix:added check on ressources (aka textures)

This commit is contained in:
B.Goulard 2024-12-17 17:08:21 +01:00
parent 85cd0d2989
commit eda859f200
4 changed files with 32 additions and 22 deletions

View file

@ -6,7 +6,7 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */
/* Updated: 2024/12/16 14:15:43 by bgoulard ### ########.fr */
/* Updated: 2024/12/17 16:52:53 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -138,6 +138,7 @@ typedef enum e_error
ERROR_CLI,
ERROR_MLX,
ERROR_TEXTURE_FORMAT,
ERROR_TEXTURE_MISSING,
ERROR_IMPLEM,
} t_error;

View file

@ -6,7 +6,7 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/01 17:46:52 by bgoulard #+# #+# */
/* Updated: 2024/12/16 14:25:52 by bgoulard ### ########.fr */
/* Updated: 2024/12/17 16:58:30 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -68,5 +68,13 @@ void *load_textures(void *data)
return (NULL);
i++;
}
i = 0;
errno = 0;
while (i < sizeof(info->map.texture_) / sizeof(info->map.texture_[0]))
{
if (info->map.texture_[i].img == NULL || info->map.texture[i] == NULL)
return (sv_errno(info, ERROR_TEXTURE_MISSING), NULL);
i++;
}
return (info);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 11:09:00 by rparodi #+# #+# */
/* Updated: 2024/12/16 15:17:33 by bgoulard ### ########.fr */
/* Updated: 2024/12/17 17:06:42 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,22 +21,23 @@
const char **get_error_message(void)
{
static const char *error_messages[] = {
[NO_ERROR] = "no error",
[ERROR_UNKNOWN] = "unknown error",
[ERROR_OPEN_FILE] = "could not open file",
[ERROR_READ_FILE] = "could not read file",
[ERROR_EXTENSION_FILE] = "bad file extension",
[ERROR_NAME_FILE] = "invalid file name",
[ERROR_MISSING_FILE] = "missing file",
[ERROR_MALLOC] = "malloc error",
[ERROR_PARSE] = "parse error",
[ERROR_MAP_OPEN] = "map open error",
[ERROR_PARSE_BG_COLOR_FORMAT] = "bad format for background color",
[ERROR_PARSE_ALREADY_SET] = "variable was set multiple times",
[ERROR_CLI] = "cli error",
[ERROR_MLX] = "mlx error",
[ERROR_TEXTURE_FORMAT] = "texture format error",
[ERROR_IMPLEM] = "not implemented",
[NO_ERROR] = "no error",
[ERROR_UNKNOWN] = "unknown error",
[ERROR_OPEN_FILE] = "could not open file",
[ERROR_READ_FILE] = "could not read file",
[ERROR_EXTENSION_FILE] = "bad file extension",
[ERROR_NAME_FILE] = "invalid file name",
[ERROR_MISSING_FILE] = "missing file",
[ERROR_MALLOC] = "malloc error",
[ERROR_PARSE] = "parse error",
[ERROR_MAP_OPEN] = "map open error",
[ERROR_PARSE_BG_COLOR_FORMAT] = "bad format for background color",
[ERROR_PARSE_ALREADY_SET] = "variable was set multiple times",
[ERROR_CLI] = "cli error",
[ERROR_MLX] = "mlx error",
[ERROR_TEXTURE_FORMAT] = "texture format error",
[ERROR_IMPLEM] = "not implemented",
[ERROR_TEXTURE_MISSING] = "texture missing",
};
return (error_messages);
@ -44,7 +45,7 @@ const char **get_error_message(void)
void c3_perror(t_info *info)
{
const char **errs_msg = get_error_message();
const char **errs_msg = get_error_message();
if (info->last_error == NO_ERROR)
return ;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
/* Updated: 2024/12/16 15:20:34 by bgoulard ### ########.fr */
/* Updated: 2024/12/17 16:55:25 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,7 +43,7 @@ void run_cub3d(t_info *info)
if (info->cli_ctx.debug)
ft_putstr_fd("no debug mod on production run", STDERR_FILENO);
if (info->last_error != NO_ERROR)
return (c3_perror(info));
return ;
if (info->cli_ctx.no_graphics == true)
return ;
info->camera.screen_buff = mlx_new_image(info->mlx_ptr, info->screen_size.x,