fix all leaks
This commit is contained in:
parent
8ad8eb1fbc
commit
a2a0a91495
2 changed files with 31 additions and 17 deletions
30
src/main.c
30
src/main.c
|
@ -6,7 +6,7 @@
|
||||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/31 16:57:40 by mc #+# #+# */
|
/* 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 "const.h"
|
||||||
# include "global.h"
|
# include "global.h"
|
||||||
|
|
||||||
|
static int g_return_value = 0;
|
||||||
|
|
||||||
static void draw_screen(void)
|
static void draw_screen(void)
|
||||||
{
|
{
|
||||||
void *img_ptr;
|
void *img_ptr;
|
||||||
|
@ -26,7 +28,10 @@ static void draw_screen(void)
|
||||||
img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
|
img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
img_data = get_data_addr(img_ptr);
|
img_data = get_data_addr(img_ptr);
|
||||||
if (!img_data)
|
if (!img_data)
|
||||||
exit(1);
|
{
|
||||||
|
g_return_value = 1;
|
||||||
|
mlx_loop_end(g_mlx);
|
||||||
|
}
|
||||||
render(img_data);
|
render(img_data);
|
||||||
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
|
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
|
||||||
mlx_destroy_image(g_mlx, img_ptr);
|
mlx_destroy_image(g_mlx, img_ptr);
|
||||||
|
@ -36,10 +41,7 @@ static void loop(void)
|
||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
if (g_input_actions.quit)
|
if (g_input_actions.quit)
|
||||||
{
|
mlx_loop_end(g_mlx);
|
||||||
mlx_destroy_window(g_mlx, g_win);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
draw_screen();
|
draw_screen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +58,24 @@ int main(int argc, char *argv[])
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
printf("Syntax: %s <map.cub>\n", argv[0]);
|
printf("Syntax: %s <map.cub>\n", argv[0]);
|
||||||
return (1);
|
g_return_value = 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (!map_from_file(&g_map, argv[1]))
|
if (!map_from_file(&g_map, argv[1]))
|
||||||
return (1);
|
g_return_value = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
|
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
|
||||||
input_init(g_win);
|
input_init(g_win);
|
||||||
mlx_loop_hook(g_mlx, loop_hook, NULL);
|
mlx_loop_hook(g_mlx, loop_hook, NULL);
|
||||||
draw_screen();
|
draw_screen();
|
||||||
mlx_loop(g_mlx);
|
mlx_loop(g_mlx);
|
||||||
return (0);
|
mlx_destroy_window(g_mlx, g_win);
|
||||||
|
map_destroy(&g_map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mlx_destroy_display(g_mlx);
|
||||||
|
free(g_mlx);
|
||||||
|
return (g_return_value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */
|
/* 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 "stream.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
const t_map_mapping_element g_map_mapping[] = {
|
const t_map_mapping_element g_map_mapping[] = {
|
||||||
{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}},
|
{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}},
|
||||||
|
@ -80,8 +81,9 @@ void map_destroy(t_map *map)
|
||||||
d = 0;
|
d = 0;
|
||||||
while (d < 4)
|
while (d < 4)
|
||||||
{
|
{
|
||||||
free((void *)map->textures[d].image);
|
mlx_destroy_image(g_mlx, map->textures[d].image);
|
||||||
free((void *)map->texture_srcs[d]);
|
free((void *)map->texture_srcs[d]);
|
||||||
|
d++;
|
||||||
}
|
}
|
||||||
free(map->cases);
|
free(map->cases);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue