From d503f3c1972c02c5c3d8f4e8bb920f49f69de66d Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 4 Feb 2025 23:32:40 +0100 Subject: [PATCH] fix: windows build with zig 0.14.0-dev.3039 --- build.zig.zon | 4 ++-- src/main.zig | 6 +++++- src/renderer/win32/renderer.zig | 38 +++++++++++++++++++++++++++++---- src/win32/dwrite.zig | 4 ++-- src/win32/gui.zig | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 1ee99ab..4121e69 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -18,8 +18,8 @@ .hash = "1220220dbc7fe91c1c54438193ca765cebbcb7d58f35cdcaee404a9d2245a42a4362", }, .thespian = .{ - .url = "https://github.com/neurocyte/thespian/archive/063c441c30aafd212b4d8e97555590594855a082.tar.gz", - .hash = "1220d04b3ac1fd1584796d8047a24cccca834592bb2ee7175e1692a1fc6d6d791fb1", + .url = "https://github.com/neurocyte/thespian/archive/eb9b8a3dcfbd15e95195951fab0505c337927f39.tar.gz", + .hash = "1220caa6ad6a0fa724c5ee13b45add9e87c57d44fd91c7731f659470f88359e1cb64", }, .themes = .{ .url = "https://github.com/neurocyte/flow-themes/releases/download/master-618a7801d3383049adfe18cc09f5f5086c66995f/flow-themes.tar.gz", diff --git a/src/main.zig b/src/main.zig index 497445f..bee7368 100644 --- a/src/main.zig +++ b/src/main.zig @@ -32,7 +32,11 @@ pub const std_options: std.Options = .{ const renderer = @import("renderer"); -pub const panic = if (@hasDecl(renderer, "panic")) renderer.panic else std.builtin.default_panic; +pub const panic = if (@hasDecl(renderer, "panic")) renderer.panic else default_panic; + +fn default_panic(msg: []const u8, _: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn { + return std.debug.defaultPanic(msg, ret_addr); +} pub fn main() anyerror!void { if (builtin.os.tag == .linux) { diff --git a/src/renderer/win32/renderer.zig b/src/renderer/win32/renderer.zig index 6c63388..192f279 100644 --- a/src/renderer/win32/renderer.zig +++ b/src/renderer/win32/renderer.zig @@ -18,8 +18,38 @@ pub const StyleBits = @import("tuirenderer").style; const gui = @import("gui"); const DropWriter = gui.DropWriter; pub const style = StyleBits; +pub const styles = @import("tuirenderer").styles; -pub const panic = win32.messageBoxThenPanic(.{ .title = "Flow Panic" }); +pub const panic = messageBoxThenPanic(.{ .title = "Flow Panic" }); + +threadlocal var thread_is_panicing = false; +fn messageBoxThenPanic( + opt: struct { + title: [:0]const u8, + style: win32.MESSAGEBOX_STYLE = .{ .ICONASTERISK = 1 }, + // TODO: add option/logic to include the stacktrace in the messagebox + }, +) std.builtin.PanicFn { + return struct { + pub fn panic( + msg: []const u8, + _: ?*std.builtin.StackTrace, + ret_addr: ?usize, + ) noreturn { + if (!thread_is_panicing) { + thread_is_panicing = true; + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + const msg_z: [:0]const u8 = if (std.fmt.allocPrintZ( + arena.allocator(), + "{s}", + .{msg}, + )) |msg_z| msg_z else |_| "failed allocate error message"; + _ = win32.MessageBoxA(null, msg_z, opt.title, opt.style); + } + std.debug.defaultPanic(msg, ret_addr); + } + }.panic; +} allocator: std.mem.Allocator, vx: vaxis.Vaxis, @@ -35,7 +65,7 @@ thread: ?std.Thread = null, hwnd: ?win32.HWND = null, title_buf: std.ArrayList(u16), -style: ?Style = null, +style_: ?Style = null, const global = struct { var init_called: bool = false; @@ -344,12 +374,12 @@ fn update_window_title(self: *Self) void { } pub fn set_terminal_style(self: *Self, style_: Style) void { - self.style = style_; + self.style_ = style_; self.update_window_style(); } fn update_window_style(self: *Self) void { const hwnd = self.hwnd orelse return; - if (self.style) |style_| { + if (self.style_) |style_| { if (style_.bg) |color| gui.set_window_background(hwnd, @intCast(color.color)); } } diff --git a/src/win32/dwrite.zig b/src/win32/dwrite.zig index e82a864..0bd85f2 100644 --- a/src/win32/dwrite.zig +++ b/src/win32/dwrite.zig @@ -41,12 +41,12 @@ pub const Font = struct { ); if (hr < 0) std.debug.panic( "CreateTextFormat '{}' height {d} failed, hresult=0x{x}", - .{ std.unicode.fmtUtf16le(face.slice()), size, @as(u32, @bitCast(hr)) }, + .{ std.unicode.fmtUtf16Le(face.slice()), size, @as(u32, @bitCast(hr)) }, ); } errdefer _ = text_format.IUnknown.Release(); - const cell_size = blk: { + const cell_size: XY(u16) = blk: { var text_layout: *win32.IDWriteTextLayout = undefined; { const hr = global.dwrite_factory.CreateTextLayout( diff --git a/src/win32/gui.zig b/src/win32/gui.zig index 9166b53..afd89df 100644 --- a/src/win32/gui.zig +++ b/src/win32/gui.zig @@ -145,7 +145,7 @@ fn getConfig() *gui_config { } fn getFieldDefault(field: std.builtin.Type.StructField) ?*const field.type { - return @alignCast(@ptrCast(field.default_value orelse return null)); + return @alignCast(@ptrCast(field.default_value_ptr orelse return null)); } fn getDefaultFontFace() FontFace {