aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_sort_s_t.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-25 19:27:47 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-25 19:27:47 +0100
commit94c06bc705b8598eb9ce30514f14f583f2538de8 (patch)
tree44175b996a6a219bc7c23b3eb4656b13ad039cd5 /src/ft_sort_s_t.c
parentFixed sprite parse (diff)
download42-cub3d-94c06bc705b8598eb9ce30514f14f583f2538de8.tar.gz
42-cub3d-94c06bc705b8598eb9ce30514f14f583f2538de8.tar.bz2
42-cub3d-94c06bc705b8598eb9ce30514f14f583f2538de8.tar.xz
42-cub3d-94c06bc705b8598eb9ce30514f14f583f2538de8.tar.zst
42-cub3d-94c06bc705b8598eb9ce30514f14f583f2538de8.zip
Solved segfault, fuck stack
Diffstat (limited to 'src/ft_sort_s_t.c')
-rw-r--r--src/ft_sort_s_t.c31
1 files changed, 27 insertions, 4 deletions
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 <libft.h>
#include <cub3d.h>
+#include <stdlib.h>
#include <stdint.h>
+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);
}