|
/// Create an application. We require stable pointers to do the set up, so this will create an App |
|
/// object on the heap. Call destroy when the app is complete to reset terminal state and release |
|
/// resources |
|
pub fn init(allocator: Allocator) !App { |
|
var app: App = .{ |
|
.allocator = allocator, |
|
.tty = undefined, |
|
.vx = try vaxis.init(allocator, .{ |
|
.system_clipboard_allocator = allocator, |
|
.kitty_keyboard_flags = .{ |
|
.report_events = true, |
|
}, |
|
}), |
|
.timers = std.ArrayList(vxfw.Tick){}, |
|
.wants_focus = null, |
|
.buffer = undefined, |
|
}; |
|
app.tty = try vaxis.Tty.init(&app.buffer); |
|
return app; |
|
} |
Looks like init constructs app on the stack and passes &app.buffer to Tty.init. app is then returned, which copies the struct to the caller's location. Any pointer that Tty stored to app.buffer now dangles, as it still references the old stack frame.
Even though the comment above says
We require stable pointers to do the set up, so this will create an App object on the heap
libvaxis/src/vxfw/App.zig
Lines 27 to 46 in a3ae1d5
Looks like
initconstructs app on the stack and passes&app.buffertoTty.init.appis then returned, which copies the struct to the caller's location. Any pointer thatTtystored toapp.buffernow dangles, as it still references the old stack frame.Even though the comment above says