From 0289be60ef2011274bddb4389a2772fd73f6ca3d Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:04 -0300 Subject: [PATCH] fix: dont close file handle early --- src/main.zig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 7f6e334..e2b461c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,6 +9,7 @@ const Scheduler = @import("scheduler.zig").Scheduler; const Timer = std.time.Timer; const Thread = std.Thread; const Atomic = std.atomic.Atomic; +const File = std.fs.File; const window_scale = 3; const gba_width = @import("ppu.zig").width; @@ -48,14 +49,15 @@ pub fn main() anyerror!void { var cpu = Arm7tdmi.init(&scheduler, &bus); cpu.fastBoot(); + var log_file: ?File = undefined; if (enable_logging) { - const file_name = if (is_binary) "zba.bin" else "zba.log"; - + const file_name: []const u8 = if (is_binary) "zba.bin" else "zba.log"; const file = try std.fs.cwd().createFile(file_name, .{ .read = true }); - defer file.close(); - cpu.useLogger(&file, is_binary); + + log_file = file; } + defer if (log_file) |file| file.close(); // Init Atomics var quit = Atomic(bool).init(false);