#vec macro causes stack overflow

40 messages · Page 1 of 1 (latest)

pallid lintel
#

I found a helper function to allocate boxed arrays onto the heap, but it overflows at line 8.
What could possibly cause this?

shut laurel
#

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.
steep crag
#

it never put anything on the stack

wispy bison
#

std::iter::repeat(val) would be better than [val].into_iter().cycle().

steep crag
#

but it's not needed at all

#

vec![val; N] is fine

#

there's something else

steep crag
#

can you post the error?

pallid lintel
#

After line 7 the call stack only has __chkstk

steep crag
#

then maybe you're calling it recursively?

pallid lintel
#

Maybe it being an option matters?

steep crag
#

what is an Option of?

pallid lintel
#

Some large data for the GPU

steep crag
#

well then this alone could overflow

pallid lintel
#

Allocating a single chunk works fine.

#

It's 256K or something 'size_of'

steep crag
#

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

pallid lintel
#

Is there another way to get Box<[Option<gpu::Chunk>; SIZE]> initialized to none?

shut laurel
#

The solution here is probably to make it Vec<Brick> and figure out which chunk each brick is in manually.

steep crag
#

the problem with Option<gpu::Chunk> is that to write it you need to have the whole value

#

which is big

pallid lintel
#

I guess I could just send bricks individually.

#

And let the GPU figure it out.

steep crag
#

why do you need Box<[Option<gpu::Chunk>; SIZE]>?

shut laurel
#

You can still get chunk-sized slices out of it

pallid lintel
#

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.

shut laurel
#

Is there a function to directly copy the contents of a slice to the vram without putting it on the stack?

pallid lintel
#

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.

shut laurel
#

Where does that point to?

#

not even sure if you can have a pointer to vram. I haven't done gpu stuff.

pallid lintel
#

IDK if I can find where device is implemented.

#

Anyways, thanks for the suggestions. I'll see how to reduce the size of my buffers.

#

Since there's so much friction.