From a4bd056b0721198a2e486f27b588f3ec49e10cb2 Mon Sep 17 00:00:00 2001 From: Ronald M Zielaznicki Date: Mon, 21 Oct 2024 12:09:51 -0400 Subject: [PATCH 1/6] change(core/linux/x11): call to XInitThreads must be first libx11 call --- src/core/linux/X11.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/linux/X11.zig b/src/core/linux/X11.zig index 8fe5a7ea09..f1a80c5aed 100644 --- a/src/core/linux/X11.zig +++ b/src/core/linux/X11.zig @@ -86,6 +86,7 @@ pub fn init( ) !X11 { // TODO(core): return errors.NotSupported if not supported const libx11 = try LibX11.load(); + _ = libx11.XInitThreads(); const libgl: ?LibGL = LibGL.load() catch |err| switch (err) { error.LibraryNotFound => null, else => return err, @@ -185,7 +186,6 @@ pub fn init( .libxkbcommon = try LibXkbCommon.load(), }; _ = libx11.XSetErrorHandler(errorHandler); - _ = libx11.XInitThreads(); _ = libx11.XrmInitialize(); defer _ = libx11.XFreeColormap(display, colormap); for (0..2) |i| { From d247fbb27e65a498f24bc9763f3742cf758fa252 Mon Sep 17 00:00:00 2001 From: Ronald M Zielaznicki Date: Mon, 21 Oct 2024 12:55:16 -0400 Subject: [PATCH 2/6] remove(core/linux/X11): errorHandler in favor of the more verbose default handler --- src/core/linux/X11.zig | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/core/linux/X11.zig b/src/core/linux/X11.zig index f1a80c5aed..069246c6e6 100644 --- a/src/core/linux/X11.zig +++ b/src/core/linux/X11.zig @@ -185,7 +185,6 @@ pub fn init( .surface_descriptor = surface_descriptor, .libxkbcommon = try LibXkbCommon.load(), }; - _ = libx11.XSetErrorHandler(errorHandler); _ = libx11.XrmInitialize(); defer _ = libx11.XFreeColormap(display, colormap); for (0..2) |i| { @@ -442,12 +441,6 @@ const LibXkbCommon = struct { } }; -fn errorHandler(display: ?*c.Display, event: [*c]c.XErrorEvent) callconv(.C) c_int { - _ = display; - log.err("X11: error code {d}\n", .{event.*.error_code}); - return 0; -} - fn createStandardCursor(x11: *X11, shape: CursorShape) !c.Cursor { if (x11.libxcursor) |libxcursor| { const theme = libxcursor.XcursorGetTheme(x11.display); From 653fbabefc2533920fd6df874c6aab5c5f211f16 Mon Sep 17 00:00:00 2001 From: Ronald M Zielaznicki Date: Mon, 21 Oct 2024 13:16:53 -0400 Subject: [PATCH 3/6] change(Core): deinit platform after GPU backend release --- src/Core.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Core.zig b/src/Core.zig index 6c72cc37ce..d9e5cf7c4c 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -355,13 +355,21 @@ pub fn deinit(entities: *mach.Entities.Mod, core: *Mod) !void { } } - state.platform.deinit(); + // GPU backend (ie. d3d12, metal, opengl, vulkan) + // + // Must be done BEFORE platform deinit. + // Otherwise, we enter a race condition where GPU might try to present + // to the window server. state.swap_chain.release(); state.queue.release(); state.device.release(); state.surface.release(); state.adapter.release(); state.instance.release(); + + // Platform (ie. Windows, MacOS, Linux X11 or Wayland) + state.platform.deinit(); + state.events.deinit(); } From 85c2c17376b5d46d7557c37376c7a508ebac32f4 Mon Sep 17 00:00:00 2001 From: Ronald M Zielaznicki Date: Mon, 21 Oct 2024 13:25:31 -0400 Subject: [PATCH 4/6] add(core/linux/X11): comment to explain why XInitThreads is called first --- src/core/linux/X11.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/linux/X11.zig b/src/core/linux/X11.zig index 069246c6e6..8c22340d09 100644 --- a/src/core/linux/X11.zig +++ b/src/core/linux/X11.zig @@ -86,6 +86,10 @@ pub fn init( ) !X11 { // TODO(core): return errors.NotSupported if not supported const libx11 = try LibX11.load(); + + // Xlibx11.XInitThreads must be called first + // + // if not, 'Unknown sequence number while processing queue' errors occur. _ = libx11.XInitThreads(); const libgl: ?LibGL = LibGL.load() catch |err| switch (err) { error.LibraryNotFound => null, From 6ac4b9318ef3c553fe2a14786bc7a3f973203182 Mon Sep 17 00:00:00 2001 From: Ronald M Zielaznicki Date: Mon, 21 Oct 2024 13:28:05 -0400 Subject: [PATCH 5/6] chore(Core): oxford commas are important --- src/Core.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core.zig b/src/Core.zig index d9e5cf7c4c..05997b919a 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -357,7 +357,7 @@ pub fn deinit(entities: *mach.Entities.Mod, core: *Mod) !void { // GPU backend (ie. d3d12, metal, opengl, vulkan) // - // Must be done BEFORE platform deinit. + // Must be released BEFORE platform deinit. // Otherwise, we enter a race condition where GPU might try to present // to the window server. state.swap_chain.release(); @@ -367,7 +367,7 @@ pub fn deinit(entities: *mach.Entities.Mod, core: *Mod) !void { state.adapter.release(); state.instance.release(); - // Platform (ie. Windows, MacOS, Linux X11 or Wayland) + // Platform (ie. Windows, MacOS, Linux X11, or Wayland) state.platform.deinit(); state.events.deinit(); From a105e00af7ebb31af1e32f92b6aad436375a3bdc Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 25 Oct 2024 11:44:33 -0700 Subject: [PATCH 6/6] revise comments --- src/Core.zig | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Core.zig b/src/Core.zig index 05997b919a..631ff29609 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -355,11 +355,8 @@ pub fn deinit(entities: *mach.Entities.Mod, core: *Mod) !void { } } - // GPU backend (ie. d3d12, metal, opengl, vulkan) - // - // Must be released BEFORE platform deinit. - // Otherwise, we enter a race condition where GPU might try to present - // to the window server. + // GPU backend must be released BEFORE platform deinit, otherwise we may enter a race + // where the GPU might try to present to the window server. state.swap_chain.release(); state.queue.release(); state.device.release(); @@ -367,7 +364,7 @@ pub fn deinit(entities: *mach.Entities.Mod, core: *Mod) !void { state.adapter.release(); state.instance.release(); - // Platform (ie. Windows, MacOS, Linux X11, or Wayland) + // Deinit the platform state.platform.deinit(); state.events.deinit();