fix(virtual_list): Move footer display buffer to state struct

- Added footer_display_buf and footer_display_len to VirtualListState
- Fixes use-after-return bug: stack buffer passed to pushCommand() was
  invalidated when function returned, causing corrupted display in
  deferred rendering
This commit is contained in:
reugenio 2025-12-25 22:03:52 +01:00
parent ae55ea5488
commit 1c284ed0f6
2 changed files with 15 additions and 5 deletions

View file

@ -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();
// =========================================================================

View file

@ -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,
));
}