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

Conversation

@yusefnapora
Copy link
Contributor

commented Aug 10, 2015

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.

Fix invalid CGContext when one dimension of destination size == 0
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

@yusefnapora yusefnapora deleted the yusefnapora:fix-invalid-cgcontext branch Aug 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.