Repository navigation
Show the actual error message in the error popup #2263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
20f8163
c4e9263
6ec5bcc
892abd5
6e1a310
b199c67
e2126a2
d144b2d
43dc1ac
e91a84f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,10 @@ const Label = @import("../components/Label.zig"); | |||||
| const VerticalList = @import("../components/VerticalList.zig"); | ||||||
| const Button = @import("../components/Button.zig"); | ||||||
|
|
||||||
| var errorCount: u32 = 0; | ||||||
| var errorText: ?[]const u8 = null; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make your life easy: Allocators will ignore zero-length allocations.
Suggested change
|
||||||
| var fileExplorerIcon: Texture = undefined; | ||||||
| var isOpen: bool = false; | ||||||
|
|
||||||
| pub var window = GuiWindow{ | ||||||
| .contentSize = Vec2f{128, 64}, | ||||||
|
|
@@ -30,22 +33,50 @@ pub fn init() void { | |||||
|
|
||||||
| pub fn deinit() void { | ||||||
| fileExplorerIcon.deinit(); | ||||||
| if (errorText != null) { | ||||||
| main.globalAllocator.free(errorText.?); | ||||||
| errorText = null; | ||||||
| } | ||||||
|
thecreare marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| fn openLog() void { | ||||||
| main.files.openDirInWindow("logs"); | ||||||
| } | ||||||
|
|
||||||
| pub fn raiseError(newText: []const u8) void { | ||||||
| if (isOpen) { | ||||||
| errorCount += 1; | ||||||
| onClose(); | ||||||
| onOpen(); | ||||||
| } else { | ||||||
| if (errorText != null) main.globalAllocator.free(errorText.?); | ||||||
|
thecreare marked this conversation as resolved.
Outdated
|
||||||
| errorText = main.globalAllocator.dupe(u8, newText); | ||||||
| errorCount = 0; | ||||||
| gui.openWindowFromRef(&window); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| const padding: f32 = 8; | ||||||
| pub fn update() void { | ||||||
| if (main.Window.Gamepad.wereControllerMappingsDownloaded()) { | ||||||
| gui.closeWindowFromRef(&window); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| const singleErrorFmtText = "#ff0000{s}"; | ||||||
| const multipleErrorFmtText = "#ff0000{s}\n#ffff00And {d} more...\nCheck the logs for details."; | ||||||
|
|
||||||
| pub fn onOpen() void { | ||||||
| isOpen = true; | ||||||
| const list = VerticalList.init(.{padding, 16 + padding}, 300, 16); | ||||||
| list.add(Label.init(.{padding, 16 + padding}, 128, "#ffff00The game encountered errors. Check the logs for details", .center)); | ||||||
| var str: []const u8 = undefined; | ||||||
| if (errorCount == 0) { | ||||||
| str = std.fmt.allocPrint(main.stackAllocator.allocator, singleErrorFmtText, .{errorText.?}) catch unreachable; | ||||||
| } else { | ||||||
| str = std.fmt.allocPrint(main.stackAllocator.allocator, multipleErrorFmtText, .{errorText.?, errorCount}) catch unreachable; | ||||||
| } | ||||||
| defer main.stackAllocator.free(str); | ||||||
| list.add(Label.init(.{padding, 16 + padding}, 256, str, .center)); | ||||||
| list.add(Button.initIcon(.{0, 0}, .{16, 16}, fileExplorerIcon, false, .init(openLog))); | ||||||
| list.finish(.center); | ||||||
| window.rootComponent = list.toComponent(); | ||||||
|
|
@@ -54,6 +85,7 @@ pub fn onOpen() void { | |||||
| } | ||||||
|
|
||||||
| pub fn onClose() void { | ||||||
| isOpen = false; | ||||||
| if (window.rootComponent) |*comp| { | ||||||
| comp.deinit(); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,6 @@ fn cacheString(comptime str: []const u8) []const u8 { | |
| var logFile: ?std.Io.File = undefined; | ||
| var logFileTs: ?std.Io.File = undefined; | ||
| var supportsANSIColors: bool = undefined; | ||
| var openingErrorWindow: bool = false; | ||
| // overwrite the log function: | ||
| pub const std_options: std.Options = .{ // MARK: std_options | ||
| .log_level = .debug, | ||
|
|
@@ -136,10 +135,8 @@ noinline fn runtimeLogFn(level: std.log.Level, format: []const u8, args: []const | |
| logToStdErr("[{s}]: {s}{s}", .{filePrefix, writer.buffered(), fileSuffix}); | ||
| } | ||
|
|
||
| if (level == .err and !openingErrorWindow and !settings.launchConfig.headlessServer) { | ||
| openingErrorWindow = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exists to prevent infinite recursion when there is an error while trying to open the error window. |
||
| gui.openWindow("error_prompt"); | ||
| openingErrorWindow = false; | ||
| if (level == .err and !settings.launchConfig.headlessServer) { | ||
| gui.windowlist.error_prompt.raiseError(writer.buffered()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.