fix crashes on close

This commit is contained in:
Mitchell Hashimoto
2023-02-22 14:58:20 -08:00
parent 913131c8f1
commit 9e4560043a
2 changed files with 11 additions and 4 deletions

View File

@ -109,9 +109,7 @@ pub fn tick(self: *App, rt_app: *apprt.runtime.App) !bool {
while (i < self.surfaces.items.len) { while (i < self.surfaces.items.len) {
const surface = self.surfaces.items[i]; const surface = self.surfaces.items[i];
if (surface.shouldClose()) { if (surface.shouldClose()) {
surface.deinit(); rt_app.closeSurface(surface);
_ = self.surfaces.swapRemove(i);
self.surface_pool.destroy(surface);
continue; continue;
} }

View File

@ -86,6 +86,12 @@ pub const App = struct {
errdefer surface.deinit(); errdefer surface.deinit();
} }
/// Close the given surface.
pub fn closeSurface(self: *App, surface: *Surface) void {
surface.deinit();
self.app.surface_pool.destroy(surface);
}
fn glfwErrorCallback(code: glfw.ErrorCode, desc: [:0]const u8) void { fn glfwErrorCallback(code: glfw.ErrorCode, desc: [:0]const u8) void {
std.log.warn("glfw error={} message={s}", .{ code, desc }); std.log.warn("glfw error={} message={s}", .{ code, desc });
@ -237,7 +243,10 @@ pub const Surface = struct {
} }
pub fn deinit(self: *Surface) void { pub fn deinit(self: *Surface) void {
// First clean up our core surface so that all the rendering and IO stop. // Remove ourselves from the list of known surfaces in the app.
self.core_surface.app.deleteSurface(self);
// Clean up our core surface so that all the rendering and IO stop.
self.core_surface.deinit(); self.core_surface.deinit();
var tabgroup_opt: if (App.Darwin.enabled) ?objc.Object else void = undefined; var tabgroup_opt: if (App.Darwin.enabled) ?objc.Object else void = undefined;