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:
parent
ae55ea5488
commit
1c284ed0f6
2 changed files with 15 additions and 5 deletions
|
|
@ -112,6 +112,14 @@ pub const VirtualListState = struct {
|
||||||
/// Frame counter para animaciones
|
/// Frame counter para animaciones
|
||||||
frame_count: u32 = 0,
|
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();
|
const Self = @This();
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
|
||||||
|
|
@ -710,7 +710,7 @@ fn drawFooter(
|
||||||
colors.header_background,
|
colors.header_background,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Format count
|
// Format count (usar buffers temporales solo para strings intermedios)
|
||||||
var count_buf: [64]u8 = undefined;
|
var count_buf: [64]u8 = undefined;
|
||||||
const count_info = list_state.getDisplayCount();
|
const count_info = list_state.getDisplayCount();
|
||||||
const count_str = count_info.format(&count_buf);
|
const count_str = count_info.format(&count_buf);
|
||||||
|
|
@ -725,14 +725,16 @@ fn drawFooter(
|
||||||
else
|
else
|
||||||
"-";
|
"-";
|
||||||
|
|
||||||
// Combine: "pos de total"
|
// Combine: "pos de total" - USAR BUFFER PERSISTENTE del state
|
||||||
var display_buf: [96]u8 = undefined;
|
// IMPORTANTE: Los buffers de stack se invalidan al retornar. El render
|
||||||
const display_str = std.fmt.bufPrint(&display_buf, "{s} de {s}", .{ pos_str, count_str }) catch "...";
|
// 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(
|
ctx.pushCommand(Command.text(
|
||||||
bounds.x + 4,
|
bounds.x + 4,
|
||||||
bounds.y + 2,
|
bounds.y + 2,
|
||||||
display_str,
|
list_state.footer_display_buf[0..list_state.footer_display_len],
|
||||||
colors.text,
|
colors.text,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue