Correction leaks sur un probleme de texture

This commit is contained in:
Etienne Rey-bethbeder
2023-05-19 17:54:06 +02:00
parent 415b6e42e3
commit 42d1359904
9 changed files with 31 additions and 20 deletions

View File

@ -6,19 +6,33 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
/* Updated: 2023/05/11 16:16:00 by erey-bet ### ########.fr */
/* Updated: 2023/05/19 17:49:02 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "game.h"
void destroy(t_game *game)
int destroy(t_game *game)
{
mlx_delete_texture(game->textures[0]);
mlx_delete_texture(game->textures[1]);
mlx_delete_texture(game->textures[2]);
mlx_delete_texture(game->textures[3]);
mlx_terminate(game->mlx);
if (game->textures[0])
{
mlx_delete_texture(game->textures[0]);
if (game->textures[1])
{
mlx_delete_texture(game->textures[1]);
if (game->textures[2])
{
mlx_delete_texture(game->textures[2]);
if (game->textures[3])
{
mlx_delete_texture(game->textures[3]);
if (game->mlx)
mlx_terminate(game->mlx);
}
}
}
}
return (1);
}
int start_game(t_map map)
@ -26,17 +40,17 @@ int start_game(t_map map)
t_game game;
if (init(map, &game))
return (1);
return (destroy(&game));
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
if (!game.window)
{
mlx_terminate(game.mlx);
return (1);
return (destroy(&game));
}
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
{
mlx_terminate(game.mlx);
return (1);
return (destroy(&game));
}
raycasting(&game);
mlx_key_hook(game.mlx, manage, &game);

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */
/* Updated: 2023/05/11 15:40:16 by erey-bet ### ########.fr */
/* Updated: 2023/05/19 17:03:52 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,13 +55,13 @@ int init_textures(t_map map, mlx_texture_t *textures[4])
int init(t_map map, t_game *game)
{
if (init_textures(map, game->textures))
return (2);
game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true);
if (!game->mlx)
return (1);
game->map = map;
init_ply(map, &game->ply);
init_ray(&game->ray);
if (init_textures(map, game->textures))
return (1);
return (0);
}