diff --git a/src/App.zig b/src/App.zig index 9ebf7d698..510bb1a0a 100644 --- a/src/App.zig +++ b/src/App.zig @@ -59,6 +59,10 @@ pub const Darwin = struct { /// up the renderer state, compiles the shaders, etc. This is the primary /// "startup" logic. pub fn create(alloc: Allocator, config: *const Config) !*App { + // Initialize glfw + try glfw.init(.{}); + errdefer glfw.terminate(); + // The mailbox for messaging this thread var mailbox = try Mailbox.create(alloc); errdefer mailbox.destroy(alloc); @@ -111,6 +115,9 @@ pub fn destroy(self: *App) void { if (comptime builtin.target.isDarwin()) self.darwin.deinit(); self.mailbox.destroy(self.alloc); self.alloc.destroy(self); + + // Close our windowing runtime + glfw.terminate(); } /// Wake up the app event loop. This should be called after any messages diff --git a/src/main.zig b/src/main.zig index fd25118f5..8a74c0852 100644 --- a/src/main.zig +++ b/src/main.zig @@ -131,10 +131,6 @@ pub fn main() !void { // We want to log all our errors glfw.setErrorCallback(glfwErrorCallback); - // Initialize glfw - try glfw.init(.{}); - defer glfw.terminate(); - // Run our app var app = try App.create(alloc, &config); defer app.destroy();