initialize glfw in app

This commit is contained in:
Mitchell Hashimoto
2022-12-30 15:48:45 -08:00
parent 13111a1fe6
commit 83f5d29ae2
2 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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();