Skip to content

Fix crash when compressing PDF files - #5

Open
hello-hugo-o wants to merge 1 commit into
nuance-dev:masterfrom
hello-hugo-o:fix/pdf-compression-metal-crash
Open

hello-hugo-o wants to merge 1 commit into
nuance-dev:masterfrom
hello-hugo-o:fix/pdf-compression-metal-crash

Conversation

@hello-hugo-o

Copy link
Copy Markdown

Compressing a PDF crashes the app in debug builds with:

validateComputeFunctionArguments:1077: failed assertion Compute Function(xdr::convert_image_to_image_reduce): the offset into the buffer imgOut that is bound at buffer index 2 must be a multiple of 32 but was set to 144.

compressPDFPage rendered each page with NSImage.lockFocus(), which goes through a Metal image conversion path that fails Metal API validation.

Changes

  • Render each page into an explicit sRGB CGContext bitmap (CPU) instead of lockFocus
  • Fill a white background first, so transparent areas don't turn black in the JPEG
  • Render at 2× (same quality as before on Retina displays), and keep the page's original point size
  • Encode the JPEG with ImageIO (CGImageDestination), same 0.5 quality, instead of a TIFF → bitmap → JPEG round-trip

Testing

  • Builds in Debug and Release
  • Compressed a PDF with the Release build: no crash, output PDF opens correctly
  • Image compression (JPG) unaffected

🤖 Generated with Claude Code

Rendering PDF pages with NSImage.lockFocus goes through a Metal
conversion path (xdr::convert_image_to_image_reduce) that fails Metal
API validation in debug builds with a buffer offset alignment assertion.

Render each page into an explicit sRGB CGBitmapContext on a white
background at 2x scale instead, and encode the JPEG with ImageIO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hello-hugo-o
hello-hugo-o force-pushed the fix/pdf-compression-metal-crash branch from 14240f8 to abbca6e Compare September 29, 2026 08:58
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.

1 participant