Skip to content

Fix segfaults in new examples (use persistent_allocator)#92

Merged
meszmate merged 1 commit intofeature/examples-batch-7from
fix/example-bugs
Apr 23, 2026
Merged

Fix segfaults in new examples (use persistent_allocator)#92
meszmate merged 1 commit intofeature/examples-batch-7from
fix/example-bugs

Conversation

@meszmate
Copy link
Copy Markdown
Owner

Summary

Five of the six new examples from #91 crashed after the first frame:

Example Crash site
`braille_canvas` `braille_canvas.zig:329` rendering cell style
`rich_log` `rich_log.zig:280` indexing entries
`screen_stack` `screen_stack.zig:156` calling vtable.update
`action_system` `action.zig:138` iterating actions
`data_table` `data_table.zig:284` reading column width

Root cause

I initialized component state with `ctx.allocator` — that's the per-frame arena which resets every render. Component internals (array lists of rows, entries, columns, etc.) ended up pointing at freed memory after the first `render()`.

Fix

Switch all long-lived component initialization to `ctx.persistent_allocator`, matching the pattern already used by `examples/file_browser.zig`. Also allocate the palette `shortcut` strings on persistent in `action_system` since `CommandPalette` stores command structs by reference.

Base branch

This PR targets `feature/examples-batch-7` (#91). Once merged there, #91 will have working examples.

Test plan

  • `zig build` passes
  • `zig build test` — full suite passes
  • All six examples run for 3+ seconds and exit cleanly on `q` — no crashes

Five of the six new examples crashed with segfaults / bus errors after
the first frame because component state (DataTable rows, RichLog
entries, ScreenStack stack, ActionRegistry actions, BrailleCanvas
cells) was allocated with ctx.allocator — the per-frame arena that
resets every render.

Switch all per-component state in init() to ctx.persistent_allocator,
matching the pattern used by examples/file_browser.zig. Also allocate
palette shortcut strings on persistent in action_system since
CommandPalette stores them by reference.
@meszmate meszmate merged commit e2871e6 into feature/examples-batch-7 Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant