From 6dc12b96da135139ff6acd488b2f2c4879f1d2e2 Mon Sep 17 00:00:00 2001 From: Elias Stepanik <40958815+eliasstepanik@users.noreply.github.com> Date: Sun, 15 Jun 2025 01:11:45 +0200 Subject: [PATCH] Avoid stack overflow from large worker buffers --- .../plugins/environment/systems/voxels/meshing_gpu.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/plugins/environment/systems/voxels/meshing_gpu.rs b/client/src/plugins/environment/systems/voxels/meshing_gpu.rs index 9b5462d..d4c59f6 100644 --- a/client/src/plugins/environment/systems/voxels/meshing_gpu.rs +++ b/client/src/plugins/environment/systems/voxels/meshing_gpu.rs @@ -42,11 +42,16 @@ pub struct GpuMeshingWorker; impl ComputeWorker for GpuMeshingWorker { fn build(world: &mut World) -> AppComputeWorker { + // Allocate large temporary arrays on the heap to avoid stack overflows + let voxels = Box::new([0u32; MAX_VOXELS]); + let vertices = Box::new([VertexGpu::default(); MAX_VERTICES]); + let indices = Box::new([0u32; MAX_INDICES]); + AppComputeWorkerBuilder::new(world) - .add_storage("voxels", &[0u32; MAX_VOXELS]) + .add_storage("voxels", voxels.as_ref()) .add_uniform("params", &Params::default()) - .add_storage("vertices", &[VertexGpu::default(); MAX_VERTICES]) - .add_storage("indices", &[0u32; MAX_INDICES]) + .add_storage("vertices", vertices.as_ref()) + .add_storage("indices", indices.as_ref()) .add_storage("counts", &[0u32; 2]) .add_pass::( [1, 1, 1],