#vec macro causes stack overflow
40 messages · Page 1 of 1 (latest)
Can you try doing
let vec = [val].into_iter().cycle().take(N).collect();
```I thought they fixed the vec macro to not put the whole thing on the stack, but maybe not.
it never put anything on the stack
std::iter::repeat(val) would be better than [val].into_iter().cycle().
Now it overflows at line 7.
can you post the error?
After line 7 the call stack only has __chkstk
then maybe you're calling it recursively?
what is an Option of?
Some large data for the GPU
well then this alone could overflow
that's a lot
a couple of them on the stack at once could blow up
vec![val; N] doesn't allocate the whole thing on the stack, but it could have like 2 at once
Is there another way to get Box<[Option<gpu::Chunk>; SIZE]> initialized to none?
The solution here is probably to make it Vec<Brick> and figure out which chunk each brick is in manually.
the problem with Option<gpu::Chunk> is that to write it you need to have the whole value
which is big
why do you need Box<[Option<gpu::Chunk>; SIZE]>?
You can still get chunk-sized slices out of it
It's a staging storage of a 2D grid. I write x elements to it where x < SIZE and then send it all to the GPU.
I was hoping I could just send all the visible chunks every frame, but maybe I need to only send mutated chunks or something.
Is there a function to directly copy the contents of a slice to the vram without putting it on the stack?
The framework I use asks for a &[u8]. I haven't gotten that far to see if it crashes or not.
Looks like they do it this way ptr::copy_nonoverlapping(data.as_ptr(), staging_buffer_ptr, data.len());
And then flush the staging buffer.