Strange multi-dimensional array issue

A bit of a strange one. I am adding a simple bitmap font to my PinePhone project that is causing hair loss.

some background:
I extracted a standalone example, which runs perfectly, so this only happens on device.
I tried to see if I could catch a panic, but nothing, or the SoC crashes before it has time to send anything over the serial debugger.

The code below is just a high level overview.
Drawing the same character, as many times as I like, works perfectly. The moment I tried to draw a different character, it crashes.
By duplicating the drawChar() fn I was able to call that fn with a different char, as often as I like. So now I can draw 2 different characters as often as I like.
Drawing a 3rd different char crashes.

After 2 days trial and error, (SoC stuff is slow iterations) I traced the issue down to my mutli-dimensional array.
Removing the ‘dataSingleChar’ intermediate value holder, and dereferencing the FONT [][] directly works as expected.

From the documentation it looks like this is just array of array, so I expected the intermediate value holder to be fine and correct type?
What am I misunderstanding please?

Only other idea I had was that maybe my linker stack placement is growing over something critical. But I dont see why the stack would need to grow.

Target: PinePhone - aarch64,freestanding,none,cortex_a53
Zig: 0.14.0

const FONT = [256][16]u8{
    [_]u8{0x00,0x01,0x02,0x03, ...},
    [_]u8{0x00,0x01,0x02,0x03, ...},
    ...
};

pub fn main() void {
    drawChar(0, 0, '1');
    drawChar(1, 0, '2');
}

fn drawChar(px:usize, py:usize, pc: u8) void {
    ...
    const dataSingleChar : [16]u8 = FONT[pc]; 
    for (0..16) |y| {
        //1. SoC crash 
        drawRowWith(dataSingleChar[y]); 

        //2. works
        drawRowWith(FONT[pc][y]);
    }
}

More specific code? I didn’t reproduce your error on 0.14.1, but it works fine.

Sadly it only happens on device, so I was hoping it was just a daft mistake with my blit code. I’ll hopefully be able to test with 0.15.0 today. But thanks for checking with 0.14.1.

Probably it is just a bit of stack/memory corruption. My code is still quite delicate since I only just reached the point of LCD working and got carried away wanting ‘hello world’ :slight_smile:

I tried with 0.15.0-dev and same results, so I’ll ignore it for now, at least until my whole boot up sequence is a bit more stable. I didnt get far with the stack investigation, other than I think it grows backwards, so I guess in theory it could collide with heap. But I am doing so little at the moment it seems unlikerly. I’ll feed back if I solve it.