fix all leaks

This commit is contained in:
mcolonna 2024-11-07 15:55:54 +01:00
parent 8ad8eb1fbc
commit a2a0a91495
2 changed files with 31 additions and 17 deletions

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 16:57:40 by mc #+# #+# */
/* Updated: 2024/11/07 14:25:29 by mc ### ########.fr */
/* Updated: 2024/11/07 14:52:00 by mc ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,8 @@
# include "const.h"
# include "global.h"
static int g_return_value = 0;
static void draw_screen(void)
{
void *img_ptr;
@ -26,7 +28,10 @@ static void draw_screen(void)
img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
img_data = get_data_addr(img_ptr);
if (!img_data)
exit(1);
{
g_return_value = 1;
mlx_loop_end(g_mlx);
}
render(img_data);
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
mlx_destroy_image(g_mlx, img_ptr);
@ -36,10 +41,7 @@ static void loop(void)
{
move();
if (g_input_actions.quit)
{
mlx_destroy_window(g_mlx, g_win);
exit(0);
}
mlx_loop_end(g_mlx);
draw_screen();
}
@ -56,14 +58,24 @@ int main(int argc, char *argv[])
if (argc != 2)
{
printf("Syntax: %s <map.cub>\n", argv[0]);
return (1);
g_return_value = 1;
}
if (!map_from_file(&g_map, argv[1]))
return (1);
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
input_init(g_win);
mlx_loop_hook(g_mlx, loop_hook, NULL);
draw_screen();
mlx_loop(g_mlx);
return (0);
else
{
if (!map_from_file(&g_map, argv[1]))
g_return_value = 1;
else
{
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
input_init(g_win);
mlx_loop_hook(g_mlx, loop_hook, NULL);
draw_screen();
mlx_loop(g_mlx);
mlx_destroy_window(g_mlx, g_win);
map_destroy(&g_map);
}
}
mlx_destroy_display(g_mlx);
free(g_mlx);
return (g_return_value);
}

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */
/* Updated: 2024/11/06 19:29:59 by mc ### ########.fr */
/* Updated: 2024/11/07 15:49:39 by mc ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
#include "stream.h"
#include "player.h"
#include "global.h"
const t_map_mapping_element g_map_mapping[] = {
{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}},
@ -80,8 +81,9 @@ void map_destroy(t_map *map)
d = 0;
while (d < 4)
{
free((void *)map->textures[d].image);
mlx_destroy_image(g_mlx, map->textures[d].image);
free((void *)map->texture_srcs[d]);
d++;
}
free(map->cases);
}