Skip to content

Fix JPEG screenshots crashing on 64-bit builds - #216

Merged
j0zzz merged 1 commit into
j0zzz:masterfrom
christopherlongden:fix-64bit-jpeg-screenshot
Oct 4, 2026
Merged

j0zzz merged 1 commit into
j0zzz:masterfrom
christopherlongden:fix-64bit-jpeg-screenshot

Conversation

@christopherlongden

Copy link
Copy Markdown
Contributor

SCR_ScreenShot passes Image_WriteJPEG the bottom row and a negative width, so the image is written top-down. The row offset is computed as

scanline = &pixels[cinfo.next_scanline*width*3];

cinfo.next_scanline is an unsigned JDIMENSION, so the whole product is unsigned. On 32-bit Windows the wrapped value still lands on the right address. On LP64 builds (Linux and macOS, x86-64 or arm64) it zero-extends to an index about 4 GB past the buffer, and screenshot crashes inside jpeg_write_scanlines:

EXC_BAD_ACCESS (SIGBUS) KERN_PROTECTION_FAILURE
libjpeg.8.3.2.dylib  jsimd_rgb_ycc_convert_neon
libjpeg.8.3.2.dylib  jpeg_write_scanlines
joequake-gl          Image_WriteJPEG   image.c:865
joequake-gl          SCR_ScreenShot    gl_screen.c:1060

The fix casts next_scanline to int, so the offset is signed, which is how Image_WritePNG already does it. Windows 32-bit behaviour is unchanged.

Tested on an arm64 macOS build of current master: before the fix screenshot crashed every time; after it the JPEG is written correctly, both windowed (800×600) and fullscreen (3840×1620).

🤖 Generated with Claude Code

SCR_ScreenShot passes the bottom row and a negative width so the image
is written top-down. In Image_WriteJPEG, cinfo.next_scanline is an
unsigned JDIMENSION, so next_scanline*width*3 is computed as unsigned:
on 32-bit Windows the wrapped value lands on the right address, but on
LP64 builds (Linux, macOS) it indexes about 4 GB past the buffer and
the screenshot crashes in jpeg_write_scanlines. Cast to int so the
offset is signed, as the PNG writer already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@j0zzz
j0zzz merged commit f38cd46 into j0zzz:master Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants