From 94c06bc705b8598eb9ce30514f14f583f2538de8 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 25 Mar 2020 19:27:47 +0100 Subject: Solved segfault, fuck stack --- src/ft_sort_s_t.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/ft_sort_s_t.c') diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 24ed358..6af1d43 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -12,10 +12,27 @@ #include #include +#include #include +void + ft_alloc_dist_tab(float ***dist_tab, t_cub *cl) +{ + uint16_t i; + + if (!(*dist_tab = (float **)malloc(8 * sizeof(float*)))) + ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + i = 0; + while (i < 8) + { + if (!((*dist_tab)[i] = (float *)malloc(4096 * sizeof(float)))) + ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + i++; + } +} + static void - ft_init_st(uint16_t sprite_var, int32_t st_o[8]) + ft_init_st(uint16_t sprite_var, int32_t *st_o) { int8_t i; @@ -25,16 +42,17 @@ static void } void - ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) + ft_sort_s_t(t_cub *cl, float **dist_tab) { - int16_t i; + int16_t i; int32_t tmp; float tmp_i[4096]; i = -1; ft_init_st(cl->mlist.sprite_var, cl->mlist.st_o); while (++i < cl->mlist.sprite_var) - if (dist_tab[i][0] < dist_tab[i + 1][0]) + { + if (i < 7 && dist_tab[i][0] < dist_tab[i + 1][0]) { tmp = cl->mlist.st_o[i]; cl->mlist.st_o[i] = cl->mlist.st_o[i + 1]; @@ -44,4 +62,9 @@ void ft_memcpy(dist_tab[i + 1], tmp_i, 4096); i = -1; } + } + i = -1; + while (++i < 8) + ft_memdel((void*)&dist_tab[i]); + ft_memdel((void*)&dist_tab); } -- cgit v1.2.3