From e82972f3dbbea43c0fa9b5f6beb9e1618b829acd Mon Sep 17 00:00:00 2001 From: RadsammyT Date: Wed, 25 Mar 2026 19:04:22 -0400 Subject: [PATCH] i spent hours debugging a arraylist shenanigan --- src/main.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index b7ad9c8..4b7d72b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1082,10 +1082,14 @@ pub fn main() !void { defer state.custom_info.deinit(state.allocator); var lblIter = custom.labels.iterator(); + // NOTE: Because widgets have a pointer to the underlying Label, we have to ensure + // that the ArrayList doesn't allocate more memory than what we ensured. Otherwise + // the pointer to the Label becomes invalid. + try state.custom_info.ensureTotalCapacity(state.allocator, @intCast(custom.labels.count())); while (lblIter.next()) |i| { try state.custom_info.append(state.allocator, .{ .info = i.value_ptr.*, - .lbl = .init("", null, state.buffer.fg, state.buffer.bg, &updateCustomInfo, null), + .lbl = .init("", null, state.buffer.fg, state.buffer.bg, updateCustomInfo, null), }); var latest = &state.custom_info.items[state.custom_info.items.len - 1]; latest.info.id = latest.lbl.widget().id;