#Can't loop 256 times?

1 messages · Page 1 of 1 (latest)

tender spade
#

I am unsure why I'm getting this error or what it means:

src/main.zig:99:17: error: evaluation exceeded 1000 backwards branches
                for (0..256) |iy| {
                ^~~
src/main.zig:99:17: note: use @setEvalBranchQuota() to raise the branch limit from 1000
src/main.zig:36:34: note: called from here
    chunk: Chunk = Chunk.generate(0, 0),

I've never seen this before in any programming language, is Zig trying to do some comptime stuff on my loops?

tame canyon
#

can you show the code?

tender spade
#
    fn generate(x: i64, y: i64) Chunk {
        _ = x; _ = y;
        var buf = Chunk {};
        
        for (0..32) |ix| {
            for (0..32) |iz| {
                for (0..256) |iy| {
                    if (iy < 128) buf.blocks[ix][iy][iz] = .Stone;
                }
            }
        }
    }

I'm trying to generate some blocks to check if everything is rendering correctly

tame canyon
#

where is it called from? functions should never run at comptime unless marked so or in comptime only contexts

tender spade
#

Oh this is fascinating
here, in the struct default value (i just put it there temporarily to test it) chunk: Chunk = Chunk.generate(0, 0),
I'm used to Swift which would just add this to the autogenerated constructor and rely on the compiler to optimize it. I did not expect this to work like this

plain venture
#

yeah, in zig the default value has to be comptime-known

tender spade
#

I guess I should move it to the init function

#

Oh okay, thanks

tame canyon
#

yea not too much point in default value if you already have an init function