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;