Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Image] Fix invalid CGContext when one dimension of destination Image size == 0 #2278

Closed
wants to merge 1 commit into from
Closed

[Image] Fix invalid CGContext when one dimension of destination Image size == 0 #2278

wants to merge 1 commit into from

Conversation

yusefnapora
Copy link
Contributor

Addresses #1534

When an image has a known width, but a height of 0 (which can happen if flex: 1 is set on the Image element), RCTDownloadManager attempts to scale it to an invalid size, which results in a NULL CGContextRef and some scary warnings from UIKit:

 <Error>: CGContextTranslateCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

This adds a check for zero width or height to the RCTClipRect function. If either dimension is zero, it is calculated based on the aspect ratio of the source image. This ensures that we don't try to create an invalid CGContextRef, and that images with an unknown dimension are still scaled, blended, etc.

When an image has a known width, but a height of 0 (which can happen if `flex: 1` is set on the `Image` element), `RCTDownloadManager` attempts to scale it to an invalid size, which results in a `NULL` `CGContextRef` and some scary warnings from UIKit:

```
 <Error>: CGContextTranslateCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
```

This adds a check for zero width or height to the `RCTClipRect` function.  If either dimension is zero, it is calculated based on the aspect ratio of the source image.  This ensures that we don't try to create an invalid `CGContextRef`, and that images with an unknown dimension are still scaled, blended, etc.
@yusefnapora yusefnapora changed the title Fix invalid CGContext when one dimension of destination Image size == 0 [Image] Fix invalid CGContext when one dimension of destination Image size == 0 Aug 10, 2015
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 10, 2015
@yusefnapora yusefnapora deleted the fix-invalid-cgcontext branch August 13, 2015 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants