Skip to content

[vector_graphics] Fix uncaught StateError in useHtmlRenderObject on CanvasKit / iOS Safari#11685

Merged
auto-submit[bot] merged 1 commit into
flutter:mainfrom
smihica:fix/vector-graphics-state-error
May 11, 2026
Merged

[vector_graphics] Fix uncaught StateError in useHtmlRenderObject on CanvasKit / iOS Safari#11685
auto-submit[bot] merged 1 commit into
flutter:mainfrom
smihica:fix/vector-graphics-state-error

Conversation

@smihica

@smihica smihica commented May 11, 2026

Copy link
Copy Markdown
Contributor

Description

useHtmlRenderObject() only caught UnsupportedError when probing
toImageSync. CanvasKit on Mobile Safari (iOS 18.7) throws a StateError
("Unable to convert read pixels from SkImage") instead, which escapes the
try/catch and crashes the widget subtree.

This change treats both UnsupportedError and StateError as
"use the HTML render object" — the function only exists to probe and
pick a fallback.

Related Issues

Fixes flutter/flutter#186333

Tests

The failure mode is only triggered by specific CanvasKit / Mobile Safari
combinations (observed on iOS 18.7) and cannot be reproduced deterministically
in a unit test against the host's renderer. Validated against production
telemetry on iOS 18.7 Safari, where this exception is currently uncaught and
reaches users.

All existing vector_graphics and vector_graphics_compiler tests still
pass after the change.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets.
  • I linked to at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making. — see Tests above.
  • All existing and new tests are passing.

@github-actions github-actions Bot added p: vector_graphics triage-engine Should be looked at in engine triage labels May 11, 2026
@smihica smihica marked this pull request as ready for review May 11, 2026 03:31

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the vector_graphics package to version 1.2.1. It modifies useHtmlRenderObject in render_object_selection.dart to catch StateError during toImageSync calls, specifically addressing a GPU pixel-read failure observed on CanvasKit in iOS 18.7. The CHANGELOG.md and pubspec.yaml have been updated to reflect this version change and fix. I have no feedback to provide.

@smihica smihica force-pushed the fix/vector-graphics-state-error branch from 4b38cf7 to d63fe77 Compare May 11, 2026 06:17
…tmlRenderObject

useHtmlRenderObject() probes toImageSync to decide whether to use the
HTML compatibility render object. Until now it caught only
UnsupportedError, which covered the original HTML renderer. Production
telemetry now shows two more failure modes from the same probe call on
CanvasKit / Mobile Safari (iOS 18.7):

  * StateError: "Unable to convert read pixels from SkImage" thrown
    when readPixels fails at runtime.
  * NoSuchMethodError: "Null check operator used on a null value"
    surfaced from canvaskit.js wasm internals via
    Surface.createOrUpdateSurface.

Add catch clauses for both. Each one is the same observed-in-production
signal that the renderer cannot honor toImageSync, so the response is
identical to the UnsupportedError path — fall back to the HTML render
object.

The failure mode is only triggered by specific CanvasKit / iOS Safari
combinations and cannot be reproduced deterministically in a unit test
against the host renderer. Verified against production telemetry on iOS
18.7 Safari, where both exception types reach users today.

Fixes flutter/flutter#186333

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks

@gaaclarke gaaclarke requested a review from andywolff May 11, 2026 18:05

@andywolff andywolff left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gaaclarke gaaclarke added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels May 11, 2026
@auto-submit auto-submit Bot merged commit 93cbed6 into flutter:main May 11, 2026
82 checks passed
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…anvasKit / iOS Safari (flutter#11685)

## Description

`useHtmlRenderObject()` only caught `UnsupportedError` when probing
`toImageSync`. CanvasKit on Mobile Safari (iOS 18.7) throws a `StateError`
("Unable to convert read pixels from SkImage") instead, which escapes the
`try/catch` and crashes the widget subtree.

This change treats both `UnsupportedError` and `StateError` as
"use the HTML render object" — the function only exists to probe and
pick a fallback.

## Related Issues

Fixes flutter/flutter#186333

## Tests

The failure mode is only triggered by specific CanvasKit / Mobile Safari
combinations (observed on iOS 18.7) and cannot be reproduced deterministically
in a unit test against the host's renderer. Validated against production
telemetry on iOS 18.7 Safari, where this exception is currently uncaught and
reaches users.

All existing `vector_graphics` and `vector_graphics_compiler` tests still
pass after the change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: vector_graphics triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vector_graphics] useHtmlRenderObject() only catches UnsupportedError, leaks StateError from CanvasKit on iOS Safari

3 participants