From d212c7be6ce0db66189ea1863c22a1d9dd42da50 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 1 Apr 2026 23:53:28 +0900 Subject: [PATCH] bm_ao_render.rb: use pack() for binary PPM output Replace printf("%c", val) with pack("CCC") for outputting raw bytes. printf("%c") with values >= 128 produces invalid UTF-8 on CRuby, corrupting the PPM output. Also remove unused arguments from the "255\n" format string. Co-authored-by: Claude --- benchmark/bm_ao_render.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/benchmark/bm_ao_render.rb b/benchmark/bm_ao_render.rb index ddb42d5c6..d48f1e194 100644 --- a/benchmark/bm_ao_render.rb +++ b/benchmark/bm_ao_render.rb @@ -292,9 +292,7 @@ class Scene r = rad.x / nsfs g = rad.y / nsfs b = rad.z / nsfs - printf("%c", clamp(r)) - printf("%c", clamp(g)) - printf("%c", clamp(b)) + print([clamp(r), clamp(g), clamp(b)].pack("CCC")) end end end @@ -303,7 +301,7 @@ end # File.open("ao.ppm", "w") do |fp| printf("P6\n") printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT) - printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT) + printf("255\n") Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES) # Scene.new.render(256, 256, 2) # end