clean up some resources better on error

This commit is contained in:
Mitchell Hashimoto
2022-11-06 16:23:36 -08:00
parent 05cd77e7cf
commit e0db46ac97
3 changed files with 11 additions and 2 deletions

View File

@ -255,6 +255,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
// Create our terminal grid with the initial window size
var renderer_impl = try Renderer.init(alloc, font_group);
errdefer renderer_impl.deinit();
renderer_impl.background = .{
.r = config.background.r,
.g = config.background.g,

View File

@ -65,7 +65,11 @@ pub fn init(
// Create our event loop.
var loop = try libuv.Loop.init(alloc);
errdefer loop.deinit(alloc);
errdefer {
// Run the loop once to close any of our handles
_ = loop.run(.nowait) catch 0;
loop.deinit(alloc);
}
loop.setData(allocPtr);
// This async handle is used to "wake up" the renderer and force a render.

View File

@ -49,7 +49,11 @@ pub fn init(
// Create our event loop.
var loop = try libuv.Loop.init(alloc);
errdefer loop.deinit(alloc);
errdefer {
// Run the loop once to close any of our handles
_ = loop.run(.nowait) catch 0;
loop.deinit(alloc);
}
loop.setData(allocPtr);
// This async handle is used to "wake up" the renderer and force a render.