mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fix: Fixed crash when invalid texture
This commit is contained in:
parent
efe33ec6c5
commit
79e94190c1
2 changed files with 9 additions and 12 deletions
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
void destroy_texture(t_cub3d_data *data, t_img_data *data_img)
|
||||
{
|
||||
if (data)
|
||||
if (data_img)
|
||||
{
|
||||
mlx_destroy_image(data->mlx, data_img->img);
|
||||
if (data_img->img)
|
||||
mlx_destroy_image(data->mlx, data_img->img);
|
||||
}
|
||||
free(data_img);
|
||||
}
|
||||
|
|
@ -29,17 +30,13 @@ void destroy_textures(t_cub3d_data *data)
|
|||
int i;
|
||||
|
||||
if (data->no_texture)
|
||||
mlx_destroy_image(data->mlx, data->no_texture->img);
|
||||
free(data->no_texture);
|
||||
destroy_texture(data, data->no_texture);
|
||||
if (data->so_texture)
|
||||
mlx_destroy_image(data->mlx, data->so_texture->img);
|
||||
free(data->so_texture);
|
||||
destroy_texture(data, data->so_texture);
|
||||
if (data->ea_texture)
|
||||
mlx_destroy_image(data->mlx, data->ea_texture->img);
|
||||
free(data->ea_texture);
|
||||
destroy_texture(data, data->ea_texture);
|
||||
if (data->we_texture)
|
||||
mlx_destroy_image(data->mlx, data->we_texture->img);
|
||||
free(data->we_texture);
|
||||
destroy_texture(data, data->we_texture);
|
||||
i = 0;
|
||||
while (i < 6)
|
||||
destroy_texture(data, data->barricades_texture[i++]);
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ t_img_data *load_single_texture(t_cub3d_data *data, char *path)
|
|||
ft_printf("Error: textures are not the right size\n");
|
||||
destroy(data, 1);
|
||||
}
|
||||
ft_printf("image: %p\n", img);
|
||||
img_data = ft_calloc(sizeof(t_img_data), 1);
|
||||
ft_printf("image: %p\n", img);
|
||||
img_data->img = img;
|
||||
img_data->addr = mlx_get_data_addr(img_data->img,
|
||||
&img_data->bits_per_pixel, &img_data->line_length,
|
||||
|
|
@ -110,9 +110,9 @@ void init_cub3d_data(t_cub3d_data *data, char **argv)
|
|||
register_weapons(data);
|
||||
init_player(data, &data->player, data->map);
|
||||
data->screen_matrix = ft_calloc(sizeof(int), WIDTH * HEIGHT);
|
||||
load_textures(data);
|
||||
data->sprite_list = ft_calloc(sizeof(t_sprite *), MAX_SPRITES);
|
||||
ft_memset(data->sprite_distances, -1, MAX_SPRITES);
|
||||
data->door_amount = 750;
|
||||
place_base_sprites(data, data->map->map);
|
||||
load_textures(data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue