Using Zig 0.15.1 on MacOS. This could very well be user error, but I am not sure how. Maybe I am doing it wrong, or it might be a bug? I have just upgraded to 0.15.1, and the fromFilePath command panics when I do this:
const temp_filename = "/tmp/temp.out.png";
try zstbi.Image.writeToFile(img, temp_filename, format);
var temp_buffer: [4192]u8 = undefined;
debug("zigimg load file from {s}", .{temp_filename});
var image = try zigimg.Image.fromFilePath(allocator, temp_filename, &temp_buffer); // <-- panics
// var image = try zigimg.Image.fromFilePath(allocator, temp_filename, temp_buffer[0..]); // <-- panics
defer image.deinit(allocator);
[default] (debug): zigimg load file from /tmp/temp.out.png
thread 98217151 panic: reached unreachable code
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Writer.zig:2374:5: 0x10046b007 in unreachableRebase (test)
unreachable;
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Writer.zig:338:27: 0x100394513 in rebase (test)
return w.vtable.rebase(w, preserve, unused_capacity_len);
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Writer.zig:412:15: 0x10037cb37 in writableSliceGreedyPreserve (test)
try rebase(w, preserve, minimum_len);
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Writer.zig:426:56: 0x100473a07 in writableSlicePreserve (test)
const big_slice = try w.writableSliceGreedyPreserve(preserve, len);
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/compress/flate/Decompress.zig:497:45: 0x10047379b in writeMatch (test)
const dest = try w.writableSlicePreserve(flate.history_len, length);
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/compress/flate/Decompress.zig:404:39: 0x10046a2df in streamInner (test)
try writeMatch(w, length, distance);
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/compress/flate/Decompress.zig:256:23: 0x10046786b in streamFallible (test)
return streamInner(d, w, limit) catch |err| switch (err) {
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/compress/flate/Decompress.zig:179:23: 0x10046820f in streamIndirectInner (test)
_ = streamFallible(d, &writer, .limited(writer.buffer.len - writer.end)) catch |err| switch (err) {
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/compress/flate/Decompress.zig:164:31: 0x10046807f in readVec (test)
return streamIndirectInner(d);
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Reader.zig:372:37: 0x1002f4753 in readVec (test)
return n + (r.vtable.readVec(r, data[i..]) catch |err| switch (err) {
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Reader.zig:631:21: 0x1002b223b in readSliceShort (test)
i += readVec(r, &data) catch |err| switch (err) {
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/Io/Reader.zig:604:33: 0x1002dd7f7 in readSliceAll (test)
const n = try readSliceShort(r, buffer);
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/formats/png/reader.zig:376:43: 0x10033bf0b in readAllData (test)
decompress_reader.readSliceAll(current_row[(filter_stride - 1)..]) catch |err| switch (err) {
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/formats/png/reader.zig:243:41: 0x1002ecc07 in loadWithHeader (test)
result = try readAllData(read_stream, header, palette, allocator, &options, &chunk_process_data);
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/formats/png/reader.zig:176:39: 0x1002a2da3 in load (test)
result.pixels = try loadWithHeader(read_stream, &header, allocator, options);
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/formats/png.zig:73:20: 0x10027b8e7 in readImage (test)
return load(read_stream, allocator, options.get());
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/Image.zig:342:42: 0x10026fef7 in internalRead (test)
return try format_interface.readImage(allocator, read_stream);
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/Image.zig:172:24: 0x100270037 in fromFile (test)
return internalRead(allocator, &read_stream);
^
/Users/user/.cache/zig/p/zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN/src/Image.zig:166:20: 0x10027026f in fromFilePath (test)
return fromFile(allocator, file, read_buffer);
^
/Volumes/user/resources/src/export_image.zig:115:50: 0x100270db3 in exportImage (test)
var image = try zigimg.Image.fromFilePath(allocator, temp_filename, &temp_buffer);
^
/Volumes/user/resources/src/export_
7B60
image.zig:387:20: 0x100459a53 in test.export_image (test)
try exportImage(
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/compiler/test_runner.zig:130:29: 0x1003f031f in mainServer (test)
test_fn.func() catch |err| switch (err) {
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/compiler/test_runner.zig:64:26: 0x1003edb4f in main (test)
return mainServer() catch @panic("internal test runner failure");
^
/Volumes/user/zig/zig-aarch64-macos-0.15.1/lib/std/start.zig:618:22: 0x1003ed57b in main (test)
root.main();
^
???:?:?: 0x186916b97 in ??? (???)
???:?:?: 0x0 in ??? (???)
Minimal example git repo https://github.com/loftafi/zigimg_png_panic or zip panic_reading_png.zip
Using Zig 0.15.1 on MacOS. This could very well be user error, but I am not sure how. Maybe I am doing it wrong, or it might be a bug? I have just upgraded to 0.15.1, and the
fromFilePathcommand panics when I do this:Minimal example git repo https://github.com/loftafi/zigimg_png_panic or zip panic_reading_png.zip