const-void / DOOM-fire-zig

DOOM's fire algo, in zig, for 256 color terminals w/no dependencies
71 stars 14 forks source link

showDoomFire crash #13

Open paeifbnaeufbpae opened 2 months ago

paeifbnaeufbpae commented 2 months ago
thread 112849 panic: index out of bounds: index 43744, len 5856
/home/user/src/DOOM-fire-zig/src/main.zig:623:39: 0x1040873 in showDoomFire (DOOM-fire)
                spread_px = screen_buf[doFire_idx];
                                      ^
/home/user/src/DOOM-fire-zig/src/main.zig:695:17: 0x103dda9 in main (DOOM-fire)
    showDoomFire();
                ^

Zig version: 0.14.0-dev.1018+531cd177e OS: Ubuntu 24.04 LTS

Already had to make a few changes to get it compile:

diff --git a/build.zig b/build.zig
index 2c1639c..bf85ef8 100644
--- a/build.zig
+++ b/build.zig
@@ -21,6 +21,7 @@ pub fn build(b: *std.Build) void {
         .target = target,
         .optimize = optimize,
     });
+    exe.linkLibC();

     // This declares intent for the executable to be installed into the
     // standard location when the user invokes the "install" step (the default
diff --git a/src/main.zig b/src/main.zig
index b2864e3..2dc9d1f 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -43,14 +43,14 @@ var stdin: std.fs.File.Reader = undefined;
 ///////////////////////////////////

 //// consts, vars, settings
-var rand: std.rand.Random = undefined;
+var rand: std.Random = undefined;

 //// functions

 // seed & prep for rng
 pub fn initRNG() !void {
     //rnd setup -- https://ziglearn.org/chapter-2/#random-numbers
-    var prng = std.rand.DefaultPrng.init(blk: {
+    var prng = std.Random.DefaultPrng.init(blk: {
         var seed: u64 = undefined;
         try std.posix.getrandom(std.mem.asBytes(&seed));
         break :blk seed;
@@ -156,12 +156,12 @@ pub fn getTermSz(tty: std.posix.fd_t) !TermSz {
         };
     } else {
         //Linux-MacOS Case
-        var winsz = std.c.winsize{ .ws_col = 0, .ws_row = 0, .ws_xpixel = 0, .ws_ypixel = 0 };
+        var winsz = std.c.winsize{ .col = 0, .row = 0, .xpixel = 0, .ypixel = 0 };
         const rv = std.c.ioctl(tty, TIOCGWINSZ, @intFromPtr(&winsz));
         const err = std.posix.errno(rv);

         if (rv >= 0) {
-            return TermSz{ .height = winsz.ws_row, .width = winsz.ws_col };
+            return TermSz{ .height = winsz.row, .width = winsz.col };
         } else {
             std.process.exit(0);
             //TODO this is a pretty terrible way to handle issues...
TarunDaCoder commented 2 weeks ago

Yeah, I am facing this same issue as well.

Already had to make a few changes to get it compile:

I only had to add exe.linkLibC(); to build.zig to make it compile.

My zig version: 0.13.0 Terminal: Ghostty OS: Ubuntu 24.04 LTS on WSL