diff --git a/src/widgets/virtual_list/state.zig b/src/widgets/virtual_list/state.zig index 3c25cf0..f793272 100644 --- a/src/widgets/virtual_list/state.zig +++ b/src/widgets/virtual_list/state.zig @@ -112,6 +112,14 @@ pub const VirtualListState = struct { /// Frame counter para animaciones frame_count: u32 = 0, + // ========================================================================= + // Buffers persistentes para texto formateado (evitar stack buffer escape) + // ========================================================================= + // IMPORTANTE: Los buffers de stack pasados a ctx.pushCommand() se invalidan + // cuando la función retorna. El render diferido usaría memoria corrupta. + footer_display_buf: [96]u8 = undefined, + footer_display_len: usize = 0, + const Self = @This(); // ========================================================================= diff --git a/src/widgets/virtual_list/virtual_list.zig b/src/widgets/virtual_list/virtual_list.zig index 5a4c723..806ac75 100644 --- a/src/widgets/virtual_list/virtual_list.zig +++ b/src/widgets/virtual_list/virtual_list.zig @@ -710,7 +710,7 @@ fn drawFooter( colors.header_background, )); - // Format count + // Format count (usar buffers temporales solo para strings intermedios) var count_buf: [64]u8 = undefined; const count_info = list_state.getDisplayCount(); const count_str = count_info.format(&count_buf); @@ -725,14 +725,16 @@ fn drawFooter( else "-"; - // Combine: "pos de total" - var display_buf: [96]u8 = undefined; - const display_str = std.fmt.bufPrint(&display_buf, "{s} de {s}", .{ pos_str, count_str }) catch "..."; + // Combine: "pos de total" - USAR BUFFER PERSISTENTE del state + // IMPORTANTE: Los buffers de stack se invalidan al retornar. El render + // diferido necesita buffers que sobrevivan hasta después del execute(). + const display_str = std.fmt.bufPrint(&list_state.footer_display_buf, "{s} de {s}", .{ pos_str, count_str }) catch "..."; + list_state.footer_display_len = display_str.len; ctx.pushCommand(Command.text( bounds.x + 4, bounds.y + 2, - display_str, + list_state.footer_display_buf[0..list_state.footer_display_len], colors.text, )); }