add null initialisation of mlx pointers and move mb init closer to begining

This commit is contained in:
hugogogo
2022-05-02 23:36:27 +02:00
parent 75692c09a6
commit a2ed84c5e1
3 changed files with 35 additions and 33 deletions

View File

@@ -1,34 +1,15 @@
#include "cube3d.h"
static int init_txtr_img(t_img *img, void *mlx_ptr, char *path)
static void init_txtr_img(t_img *img, void *mlx_ptr, char *path)
{
img->ptr = mlx_xpm_file_to_image(mlx_ptr, path, &img->width, &img->height);
if (img->ptr == NULL)
return (1);
img->data = mlx_get_data_addr(img->ptr, &img->bpp, &img->szl, &img->ndn);
return (0);
}
void init_txtr(t_txt *txt, void *mlx_ptr)
{
if (init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_north) == 1)
mb_exit("failed to read image for texture nord", EXIT_FAILURE);
if (init_txtr_img(&txt->img_s, mlx_ptr, txt->txt_south) == 1)
{
mlx_destroy_image(mlx_ptr, txt->img_n.ptr);
mb_exit("failed to read image for texture south", EXIT_FAILURE);
}
if (init_txtr_img(&txt->img_e, mlx_ptr, txt->txt_east) == 1)
{
mlx_destroy_image(mlx_ptr, txt->img_n.ptr);
mlx_destroy_image(mlx_ptr, txt->img_s.ptr);
mb_exit("failed to read image for texture east", EXIT_FAILURE);
}
if (init_txtr_img(&txt->img_w, mlx_ptr, txt->txt_west) == 1)
{
mlx_destroy_image(mlx_ptr, txt->img_n.ptr);
mlx_destroy_image(mlx_ptr, txt->img_s.ptr);
mlx_destroy_image(mlx_ptr, txt->img_e.ptr);
mb_exit("failed to read image for texture west", EXIT_FAILURE);
}
init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_north);
init_txtr_img(&txt->img_s, mlx_ptr, txt->txt_south);
init_txtr_img(&txt->img_e, mlx_ptr, txt->txt_east);
init_txtr_img(&txt->img_w, mlx_ptr, txt->txt_west);
}