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]);
}
}