star-line

Structure for accelerating line importance sampling
git clone git://git.meso-star.fr/star-line.git
Log | Files | Refs | README | LICENSE

commit 206585bccb3a3b1f95ca53bdb869d89a87f5adf6
parent 93fd6bad7711451a4dda4056a2329ccd6271c9ff
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  4 May 2026 13:30:40 +0200

Fix a memory leak during polyline generation

To construct a polyline composed of multiple lines, a temporary vertex
buffer is used. To avoid having to allocate and deallocate this buffer
with every call to the polyline creation function, the temporary buffer
is passed as an input argument to the function and is thus reused
between calls. However, this vertex buffer was never cleared.
Consequently, the meshing algorithm did not reuse the memory space
already allocated, but allocated new memory instead. This resulted in a
vertex buffer whose final size corresponded to the amount needed to
store the mesh of all lines, which is not only unnecessary but can also
consume a huge amount of memory.

This commit simply clears the vertex buffer at the start of constructing
the polyline for each new set of lines.

Diffstat:
Msrc/sln_tree_build.c | 3+++
1 file changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/sln_tree_build.c b/src/sln_tree_build.c @@ -255,6 +255,9 @@ build_leaf_polyline_from_Nlines if(res != RES_OK) goto error; memset(NODE(0), 0, sizeof(struct sln_node)*nnodes); + /* Clean up the temporary list of vertices */ + darray_vertex_clear(&scratch->vertices); + /* The leaf node will be the first one. Its "child" representing the node of * each lines, will be store after it in the node list */ NODE(0)->offset = 1;