Skip to content

Swallow exceptions on draw, forward to onError#46964

Closed
Abbondanzo wants to merge 1 commit into
facebook:mainfrom
Abbondanzo:export-D64144596
Closed

Swallow exceptions on draw, forward to onError#46964
Abbondanzo wants to merge 1 commit into
facebook:mainfrom
Abbondanzo:export-D64144596

Conversation

@Abbondanzo
Copy link
Copy Markdown
Contributor

Summary:
Graceful degradation is better than outright crashing. When rendering images that exceed Android's memory limits, React Native applications will fatally crash. This change intervenes by swallowing the exception that Android raises and forwards it to the onError handler. As a result, no image will be rendered instead of fatally crashing.

Fresco already intervenes by default. It will raise a PoolSizeViolationException if the bitmap size exceeds memory limits set by the OS and applies a 2048 pixel maximum dimension to JPEG images, but it's still possible for these configuration limits to be removed and for images to fall just short of Fresco's memory limit. The exception is raised when we attempt to draw the bitmap, not when the bitmap is allocated in memory, so we must handle the exception here and not in Fresco.

Changelog

[Android][Fixed] - Apps will no longer fatally crash when trying to draw large images

Differential Revision: D64144596

@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 Oct 10, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D64144596

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D64144596

1 similar comment
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D64144596

Summary:
Pull Request resolved: facebook#46964

Graceful degradation is better than outright crashing. When rendering images that exceed Android's memory limits, React Native applications will fatally crash. This change intervenes by swallowing the exception that Android raises and forwards it to the `onError` handler. As a result, no image will be rendered instead of fatally crashing.

Fresco already intervenes by default. It will raise a `PoolSizeViolationException` if the bitmap size exceeds memory limits set by the OS and applies a 2048 pixel maximum dimension to JPEG images, but it's still possible for these configuration limits to be removed and for images to fall just short of Fresco's memory limit. The exception is raised when we attempt to draw the bitmap, not when the bitmap is allocated in memory, so we must handle the exception here and not in Fresco.

## Changelog

[Android][Fixed] - Apps will no longer fatally crash when trying to draw large images

Reviewed By: tdn120

Differential Revision: D64144596
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D64144596

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 483b928.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Oct 11, 2024
@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Abbondanzo in 483b928

When will my fix make it into a release? | How to file a pick request?

@Abbondanzo Abbondanzo deleted the export-D64144596 branch October 20, 2024 15:31
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. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants