Skip to content

Fix crash from boxShadow conditional canvas.save()#45780

Closed
NickGerleman wants to merge 1 commit into
facebook:mainfrom
NickGerleman:export-D60375357
Closed

Fix crash from boxShadow conditional canvas.save()#45780
NickGerleman wants to merge 1 commit into
facebook:mainfrom
NickGerleman:export-D60375357

Conversation

@NickGerleman
Copy link
Copy Markdown
Contributor

Summary:
D59300215 noticed that the drawable was leaking a clipping rect for the rest of the operations, and added a save/restore pair, but the save happens conditionally, so we can restore more often than we save, if we hit a fast path of not needing to invalidate the shadow RenderNode when drawing. This leads to the following unhandled exception:

java.lang.IllegalStateException: Underflow in restore - more restores than saves
    at android.graphics.Canvas.restore(Canvas.java:647)
    at com.facebook.react.uimanager.drawable.OutsetBoxShadowDrawable.draw(OutsetBoxShadowDrawable.kt:110)
    at android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:1019)

This change moves saving canvas context to before setting state and drawing onto the canvas, instead of the area manipulating the RenderNode.

Changelog: [Internal]

Differential Revision: D60375357

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Jul 29, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

Summary:
Pull Request resolved: facebook#45780

D59300215 noticed that the drawable was leaking a clipping rect for the rest of the operations, and added a `save/restore` pair, but the save happens conditionally, so we can restore more often than we save, if we hit a fast path of not needing to invalidate the shadow RenderNode when drawing. This leads to the following unhandled exception:

```
java.lang.IllegalStateException: Underflow in restore - more restores than saves
    at android.graphics.Canvas.restore(Canvas.java:647)
    at com.facebook.react.uimanager.drawable.OutsetBoxShadowDrawable.draw(OutsetBoxShadowDrawable.kt:110)
    at android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:1019)
```

This change moves saving canvas context to before setting state and drawing onto the canvas, instead of the area manipulating the RenderNode.

Changelog: [Internal]

Reviewed By: cortinico

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

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

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jul 29, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 496e77b.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @NickGerleman in 496e77b

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

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