fix: dont close file handle early

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-21 05:12:04 -03:00
parent 93922b65e3
commit 0289be60ef
1 changed files with 6 additions and 4 deletions

View File

@ -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);