From 726e4616db128b11e3b12403210298f5b00a59da Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 22 Dec 2024 00:53:22 +0200 Subject: [PATCH] renders: dynamic allocate buffer in *_MarkLeaves --- src/client/refresh/gl1/gl1_surf.c | 9 ++++++++- src/client/refresh/gl3/gl3_surf.c | 17 +++++++++++++---- src/client/refresh/gl4/gl4_surf.c | 17 +++++++++++++---- src/client/refresh/vk/vk_surf.c | 9 ++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index 6437b253..0ab484c6 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -1242,7 +1242,7 @@ void R_MarkLeaves(void) { const byte *vis; - YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8]; + byte *fatvis = NULL; mnode_t *node; int i; mleaf_t *leaf; @@ -1289,6 +1289,7 @@ R_MarkLeaves(void) { int c; + fatvis = malloc(((r_worldmodel->numleafs + 31) / 32) * sizeof(int)); memcpy(fatvis, vis, (r_worldmodel->numleafs + 7) / 8); vis = Mod_ClusterPVS(r_viewcluster2, r_worldmodel); c = (r_worldmodel->numleafs + 31) / 32; @@ -1331,4 +1332,10 @@ R_MarkLeaves(void) while (node); } } + + /* clean combined buffer */ + if (fatvis) + { + free(fatvis); + } } diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index 4e602efe..6200d0ed 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -797,11 +797,10 @@ void GL3_MarkLeaves(void) { const byte *vis; - YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8]; + byte *fatvis = NULL; mnode_t *node; - int i, c; + int i; mleaf_t *leaf; - int cluster; if ((gl3_oldviewcluster == gl3_viewcluster) && (gl3_oldviewcluster2 == gl3_viewcluster2) && @@ -843,6 +842,9 @@ GL3_MarkLeaves(void) /* may have to combine two clusters because of solid water boundaries */ if (gl3_viewcluster2 != gl3_viewcluster) { + int c; + + fatvis = malloc(((gl3_worldmodel->numleafs + 31) / 32) * sizeof(int)); memcpy(fatvis, vis, (gl3_worldmodel->numleafs + 7) / 8); vis = GL3_Mod_ClusterPVS(gl3_viewcluster2, gl3_worldmodel); c = (gl3_worldmodel->numleafs + 31) / 32; @@ -859,6 +861,8 @@ GL3_MarkLeaves(void) i < gl3_worldmodel->numleafs; i++, leaf++) { + int cluster; + cluster = leaf->cluster; if (cluster == -1) @@ -883,5 +887,10 @@ GL3_MarkLeaves(void) while (node); } } -} + /* clean combined buffer */ + if (fatvis) + { + free(fatvis); + } +} diff --git a/src/client/refresh/gl4/gl4_surf.c b/src/client/refresh/gl4/gl4_surf.c index 618c1235..60d95ec4 100644 --- a/src/client/refresh/gl4/gl4_surf.c +++ b/src/client/refresh/gl4/gl4_surf.c @@ -794,11 +794,10 @@ void GL4_MarkLeaves(void) { const byte *vis; - YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8]; + byte *fatvis = NULL; mnode_t *node; - int i, c; + int i; mleaf_t *leaf; - int cluster; if ((gl4_oldviewcluster == gl4_viewcluster) && (gl4_oldviewcluster2 == gl4_viewcluster2) && @@ -840,6 +839,9 @@ GL4_MarkLeaves(void) /* may have to combine two clusters because of solid water boundaries */ if (gl4_viewcluster2 != gl4_viewcluster) { + int c; + + fatvis = malloc(((gl4_worldmodel->numleafs + 31) / 32) * sizeof(int)); memcpy(fatvis, vis, (gl4_worldmodel->numleafs + 7) / 8); vis = GL4_Mod_ClusterPVS(gl4_viewcluster2, gl4_worldmodel); c = (gl4_worldmodel->numleafs + 31) / 32; @@ -856,6 +858,8 @@ GL4_MarkLeaves(void) i < gl4_worldmodel->numleafs; i++, leaf++) { + int cluster; + cluster = leaf->cluster; if (cluster == -1) @@ -880,5 +884,10 @@ GL4_MarkLeaves(void) while (node); } } -} + /* clean combined buffer */ + if (fatvis) + { + free(fatvis); + } +} diff --git a/src/client/refresh/vk/vk_surf.c b/src/client/refresh/vk/vk_surf.c index af9a7825..9ca390c2 100644 --- a/src/client/refresh/vk/vk_surf.c +++ b/src/client/refresh/vk/vk_surf.c @@ -811,7 +811,7 @@ void R_MarkLeaves(void) { const byte *vis; - YQ2_ALIGNAS_TYPE(int) byte fatvis[MAX_MAP_LEAFS / 8]; + byte *fatvis = NULL; mnode_t *node; int i; mleaf_t *leaf; @@ -858,6 +858,7 @@ R_MarkLeaves(void) { int c; + fatvis = malloc(((r_worldmodel->numleafs + 31) / 32) * sizeof(int)); memcpy(fatvis, vis, (r_worldmodel->numleafs + 7) / 8); vis = Mod_ClusterPVS(r_viewcluster2, r_worldmodel); c = (r_worldmodel->numleafs + 31) / 32; @@ -900,4 +901,10 @@ R_MarkLeaves(void) while (node); } } + + /* clean combined buffer */ + if (fatvis) + { + free(fatvis); + } }