From 75f54cd49e5b9942678d2b8a8137ca1110a785f5 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 15 Mar 2020 19:42:48 +0100 Subject: Valgrind errors fix --- src/ft_exit.c | 2 ++ src/ft_floor_cast.c | 30 +++++++++++++++--------------- src/ft_init_lists.c | 1 + src/ft_init_sfx.c | 4 ++++ src/ft_raycasting.c | 2 +- src/main.c | 16 +++++++++------- 6 files changed, 32 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ft_exit.c b/src/ft_exit.c index f1da643..80fd734 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -42,10 +42,12 @@ static void ft_free_words(clist->sfx.death); ft_free_words(clist->sfx.pain_one); ft_free_words(clist->sfx.pain_two); + ft_free_words(clist->sfx.new_lvl); ft_free_words(clist->sfx.trap); ft_free_sprites(clist->mlist.sprite_path); if (!clist->wlist.inited) ft_memdel((void**)&clist->wlist.winptr); + ft_memdel((void**)&clist); } static void diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 2eda9d8..92dcb07 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -25,23 +25,21 @@ static void { float dist; float calc; + t_rgb rgb; - if ((dist = cl->rlist.row_dist) <= 0) - dist = 0.0001; + dist = (cl->rlist.row_dist > 0) ? (cl->rlist.row_dist) : (0.0001); calc = (dist * 0.1 * cl->mlist.darklvl); calc = (calc >= 255) ? (255) : (calc); calc = (calc < 1) ? (1) : (calc); calc = (cl->mlist.darklvl > 0) ? (calc) : (1); - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = - (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * - cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = - (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * - cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = - (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * + rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2] / calc; - cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0; + rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * + cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc; + rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * + cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc; + *(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); } static void @@ -88,12 +86,12 @@ void uint16_t y; rl = &cl->rlist; - y = (cl->wlist.y_size / 2) + 1; - while (++y < cl->wlist.y_size) + y = (cl->wlist.y_size / 2); + while (y < cl->wlist.y_size) { ft_floor_cast_inits(y, rl, cl); - x = -1; - while (++x < cl->wlist.x_size) + x = 0; + while (x < cl->wlist.x_size) { if (cl->rlist.wall_bz[x] <= y) { @@ -101,6 +99,8 @@ void } rl->x_floor += cl->mlist.x_floor_step; rl->y_floor += cl->mlist.y_floor_step; + x++; } + y++; } } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 5726a5b..cd928b0 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -72,6 +72,7 @@ static int8_t i = -1; while (++i < 5) cl->key_input[i] = -1; + cl->mpid = 0; cl->ishud = 0; cl->isoldmus = 0; cl->doicast = 1; diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c index 728e410..9049250 100644 --- a/src/ft_init_sfx.c +++ b/src/ft_init_sfx.c @@ -41,6 +41,10 @@ static int8_t int8_t ft_init_sfx(t_sfx *sfx) { + sfx->death_pid = 0; + sfx->new_lvl_pid = 0; + sfx->pain_pid = 0; + sfx->trap_pid = 0; if (ft_split_sfx(&sfx->death, FT_SFX_DEATH_PATH) < 0 || ft_split_sfx(&sfx->new_lvl, FT_SFX_N_LVL_PATH) < 0 || ft_split_sfx(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 || diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index a0720ea..743dc36 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -78,7 +78,6 @@ static void cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2; if (cl->rlist.wall_b >= (int16_t)wl->y_size) cl->rlist.wall_b = wl->y_size - 1; - cl->rlist.wall_bz[i] = cl->rlist.wall_b; } void @@ -101,6 +100,7 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); + cl->rlist.wall_bz[i] = cl->rlist.wall_b; cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; i++; } diff --git a/src/main.c b/src/main.c index 43b482a..d1ff470 100644 --- a/src/main.c +++ b/src/main.c @@ -17,16 +17,18 @@ int main(int argc, const char *argv[], char *const envp[]) { - t_cub clist; + t_cub *clist; if (ft_check_map_arg(argc, argv) == FT_RET_BAD_ARGV) return (FT_RET_BAD_ARGV); - if (ft_init_cub3d(&clist) < 0) + if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) + return (FT_RET_ALLOC_ERR); + if (ft_init_cub3d(clist) < 0) return (FT_RET_FAILED_STRUCTS); - ft_parse_map(argv[1], &clist); - if (ft_init_winlx(&clist) < 0) - return (ft_exit(FT_RET_FAILED_MLX, &clist)); - ft_wall_tex_init(&clist); - ft_use_args(argc, argv, envp, &clist); + ft_parse_map(argv[1], clist); + if (ft_init_winlx(clist) < 0) + return (ft_exit(FT_RET_FAILED_MLX, clist)); + ft_wall_tex_init(clist); + ft_use_args(argc, argv, envp, clist); return (FT_RET_FINE); } -- cgit v1.2.3