Avoid stack overflow from large worker buffers

This commit is contained in:
Elias Stepanik 2025-06-15 01:11:45 +02:00
parent d05c0773c6
commit 6dc12b96da

View File

@ -42,11 +42,16 @@ pub struct GpuMeshingWorker;
impl ComputeWorker for GpuMeshingWorker {
fn build(world: &mut World) -> AppComputeWorker<Self> {
// 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::<GreedyMeshingShader>(
[1, 1, 1],