-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheap_cleanup.c
86 lines (78 loc) · 2.27 KB
/
heap_cleanup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* heap_cleanup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fatkeski <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 18:40:04 by fatkeski #+# #+# */
/* Updated: 2025/02/21 21:35:28 by fatkeski ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/cub3d.h"
void free_double_pointer(char **arr)
{
int i;
i = 0;
while (arr[i] != NULL)
{
free(arr[i]);
i++;
}
free(arr);
}
void free_elements(t_game *game)
{
if (game->elements.north)
free(game->elements.north);
if (game->elements.south)
free(game->elements.south);
if (game->elements.west)
free(game->elements.west);
if (game->elements.east)
free(game->elements.east);
}
void free_images(t_game *game)
{
if (game->img.north_texture)
free(game->img.north_texture);
if (game->img.south_texture)
free(game->img.south_texture);
if (game->img.east_texture)
free(game->img.east_texture);
if (game->img.west_texture)
free(game->img.west_texture);
}
void free_cub_surfaces(t_game *game)
{
int i;
i = 0;
while (i < 4)
{
if (game->cub_surfaces[i].addr)
{
if (game->cub_surfaces[i].img)
mlx_destroy_image(game->mlx, game->cub_surfaces[i].img);
}
i++;
}
}
void free_game_struct(t_game *game)
{
free_elements(game);
if (game->file_content)
free_double_pointer(game->file_content);
if (game->map.map_2d)
free_double_pointer(game->map.map_2d);
free_images(game);
if (game->cub_surfaces->addr)
free_cub_surfaces(game);
if (game->mlx && game->mlx_window)
mlx_destroy_window(game->mlx, game->mlx_window);
if (game->mlx_img)
mlx_destroy_image(game->mlx, game->mlx_img);
if (game->mlx)
mlx_destroy_display(game->mlx);
if (game->mlx)
free(game->mlx);
}