some mem stuff

This commit is contained in:
Willem Haffmans 2025-05-25 10:52:02 +02:00
parent 98bced2a5e
commit 6a26998064
3 changed files with 44 additions and 16 deletions

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */ /* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */
/* Updated: 2025/05/14 19:57:03 by whaffman ######## odam.nl */ /* Updated: 2025/05/24 14:27:07 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,10 +15,29 @@
void map_free(t_map *map) void map_free(t_map *map)
{ {
int i;
grid_free(map->grid, map->height); grid_free(map->grid, map->height);
free(map->north_texture); // free(map->north_texture);
free(map->south_texture); // free(map->south_texture);
free(map->west_texture); // free(map->west_texture);
free(map->east_texture); // free(map->east_texture);
if(map->texture_floor)
mlx_delete_texture(map->texture_floor);
if(map->texture_ceiling)
mlx_delete_texture(map->texture_ceiling);
while (map->n_sprites > 0)
{
map->n_sprites--;
mlx_delete_texture(map->sprites[map->n_sprites].texture);
}
free(map->sprites);
i = 4;
while (i > 0)
{
i--;
if (map->textures[i])
mlx_delete_texture(map->textures[i]);
}
// free(map->textures);
free(map); free(map);
} }

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* render_minimap.c :+: :+: :+: */ /* render_minimap.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/05/12 11:31:34 by whaffman #+# #+# */ /* Created: 2025/05/12 11:31:34 by whaffman #+# #+# */
/* Updated: 2025/05/22 14:45:12 by qmennen ### ########.fr */ /* Updated: 2025/05/22 19:40:39 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,7 +37,7 @@ static void draw_minimap_pixel(t_game *game, t_vec2_int disp, t_vec2 map)
|| game->map->grid[(int)map.y][(int)map.x] == TILE_PLAYER) || game->map->grid[(int)map.y][(int)map.x] == TILE_PLAYER)
mlx_put_pixel(img, disp.x, disp.y, 0x00ff0077); mlx_put_pixel(img, disp.x, disp.y, 0x00ff0077);
else if (game->map->grid[(int)map.y][(int)map.x] == TILE_VISITED) else if (game->map->grid[(int)map.y][(int)map.x] == TILE_VISITED)
mlx_put_pixel(img, disp.x, disp.y, 0xaaff0077); mlx_put_pixel(img, disp.x, disp.y, 0xaaff00aa);
else else
mlx_put_pixel(img, disp.x, disp.y, 0x00ff0044); mlx_put_pixel(img, disp.x, disp.y, 0x00ff0044);
} }

View File

@ -3,10 +3,10 @@
/* :::::::: */ /* :::::::: */
/* shaders.c :+: :+: */ /* shaders.c :+: :+: */
/* +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */ /* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
/* Updated: 2025/05/23 15:24:19 by whaffman ######## odam.nl */ /* Updated: 2025/05/24 13:52:26 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,6 +35,7 @@ const char *read_shader(int type)
char *shader; char *shader;
char *target; char *target;
int fd; int fd;
size_t bytes_read;
if (type == 1) if (type == 1)
target = "./assets/shaders/vert.glsl"; target = "./assets/shaders/vert.glsl";
@ -53,7 +54,15 @@ const char *read_shader(int type)
close(fd); close(fd);
return (NULL); return (NULL);
} }
read(fd, shader, 4096); bytes_read = read(fd, shader, 4096);
if (bytes_read < 0)
{
perror("Error reading shader file");
free(shader);
close(fd);
return (NULL);
}
shader[bytes_read] = '\0';
close(fd); close(fd);
return (shader); return (shader);
} }