Skip to content

fix(macos): keep the view's shadow color alive - #3129

Draft
Saad Najmi (Saadnajmi) wants to merge 1 commit into
microsoft:mainfrom
Saadnajmi:fix-macos-shadow-color
Draft

Saad Najmi (Saadnajmi) wants to merge 1 commit into
microsoft:mainfrom
Saadnajmi:fix-macos-shadow-color

Conversation

@Saadnajmi

Copy link
Copy Markdown
Collaborator

Summary:

On macOS, RCTView declares shadowColor as an assign CGColorRef property, so setShadowColor: stored the color without retaining it. +[RCTConvert CGColor:] returns the CGColor of an autoreleased NSColor (it's CF_RETURNS_NOT_RETAINED), so the color could be freed by the time didUpdateShadow read it again, for example when shadowOpacity or shadowRadius was set afterwards. That crashed.

This converts the color to an NSColor when it's set and keeps that instead. Setting the color to NULL now clears it.

Office shipped this fix (without the NULL handling) in its copy of React Native macOS 0.81.

Test Plan:

Built the same change on 0.81 in Office for macOS arm64 and x86_64, with warnings as errors. CI covers main.

On macOS, RCTView declares shadowColor as an assign CGColorRef property, so it kept
the color it was given without retaining it. That color is autoreleased, so by the
time didUpdateShadow read it, it could already be freed, which crashed.

Convert the color to an NSColor as soon as it's set, and keep that instead. Setting
it to NULL clears the color.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 33ac4470-c1d2-43c0-92ee-8407909f0f6a

This branch has not been deployed

No deployments
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