reintroduce App.create

This commit is contained in:
Mitchell Hashimoto
2025-06-27 09:09:54 -07:00
parent 1979fb92f4
commit 83690744b2
3 changed files with 22 additions and 11 deletions

View File

@@ -76,6 +76,15 @@ first: bool = true,
pub const CreateError = Allocator.Error || font.SharedGridSet.InitError;
/// Create a new app instance. This returns a stable pointer to the app
/// instance which is required for callbacks.
pub fn create(alloc: Allocator) CreateError!*App {
var app = try alloc.create(App);
errdefer alloc.destroy(app);
try app.init(alloc);
return app;
}
/// Initialize the main app instance. This creates the main window, sets
/// up the renderer state, compiles the shaders, etc. This is the primary
/// "startup" logic.
@@ -111,6 +120,14 @@ pub fn deinit(self: *App) void {
self.font_grid_set.deinit();
}
pub fn destroy(self: *App) void {
// Deinitialize the app
self.deinit();
// Free the app memory
self.alloc.destroy(self);
}
/// Tick ticks the app loop. This will drain our mailbox and process those
/// events. This should be called by the application runtime on every loop
/// tick.