Skip to content

fix(renderer): stop iOS toRawPixelData from returning leftover memory in transparent pixels - #949

Open
Marve10s wants to merge 1 commit into
margelo:mainfrom
Marve10s:fix/ios-raw-pixel-clear
Open

Marve10s wants to merge 1 commit into
margelo:mainfrom
Marve10s:fix/ios-raw-pixel-clear

Conversation

@Marve10s

@Marve10s Marve10s commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

On iOS, image.toRawPixelData() returns whatever was in memory before for transparent and translucent pixels. Exporting a transparent ImageFactory.createBlankImage(100, 100, true) right after exporting a red image returns solid red, and a 50% blue fill comes back as [80 00 7f ff] instead of [80 00 00 80]. The result can change from run to run. Android returns the image's own pixels.

When the image isn't tightly packed 32 bpp, the slow path allocates the output with ArrayBuffer.allocate, which doesn't zero memory, wraps it in a CGContext and draws the image with source-over blending. Wherever the image's alpha is below 1, the old bytes show through. That covers every transparent createBlankImage without a fill, renderer output (resize, rotate, renderInto) whose width * 4 isn't the padded row size, and 16-bit PNGs.

This clears the context before drawing, so those pixels come out as transparent black. The fast path is unchanged.

Verification

A script outside the repo compiles the renderer's image Swift files unchanged as a Mac Catalyst binary (real UIKit and CoreGraphics, with stubs for NitroModules and the generated spec types) and compares toRawPixelData() with the same image drawn into a zeroed BGRA context.

v0.2.1 and v0.3.0:

1. ImageFactory.createBlankImage(100, 100, true).toRawPixelData() after exporting a red 100x100 image
  100x100 16bpp bytesPerRow=224: wrong pixels 10000/10000  pixel 5000: got [00 00 ff ff] expected [00 00 00 00]
2. half-green/half-transparent 60x60 image, .resize(30, 30).toRawPixelData() after exporting a red 30x30 image
  30x30 32bpp bytesPerRow=128: wrong pixels 450/900  pixel 465: got [00 00 ff ff] expected [00 00 00 00]
3. createBlankImage(30, 30, true, 50% blue).toRawPixelData() after exporting a red 30x30 image
  30x30 32bpp bytesPerRow=128: wrong pixels 896/900  pixel 452: got [80 00 7f ff] expected [80 00 00 80]
4. control: opaque red 30x30 after exporting a red 30x30 image
  30x30 32bpp bytesPerRow=128: wrong pixels 0/900

This branch:

1. ImageFactory.createBlankImage(100, 100, true).toRawPixelData() after exporting a red 100x100 image
  100x100 16bpp bytesPerRow=224: wrong pixels 0/10000  
2. half-green/half-transparent 60x60 image, .resize(30, 30).toRawPixelData() after exporting a red 30x30 image
  30x30 32bpp bytesPerRow=128: wrong pixels 0/900  
3. createBlankImage(30, 30, true, 50% blue).toRawPixelData() after exporting a red 30x30 image
  30x30 32bpp bytesPerRow=128: wrong pixels 0/900  
4. control: opaque red 30x30 after exporting a red 30x30 image
  30x30 32bpp bytesPerRow=128: wrong pixels 0/900

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@Marve10s is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T13:37:52.661961Z 0597619 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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