fix(web): fix crash in Skwasm when transferring non-transferable texture sources#183799
Merged
auto-submit[bot] merged 1 commit intoflutter:masterfrom Mar 18, 2026
Merged
Conversation
…ure sources The engine was previously attempting to transfer non-transferable objects like `HTMLImageElement` to the web worker via `postMessage` when `transferOwnership` was set to `true`. This resulted in a `DataCloneError`. This change adds a check to see if the texture source is a transferable type when in multi-threaded mode. If not, it converts it to an `ImageBitmap` using `createImageBitmap` before transferring. A new test `test/ui/image_texture_source_test.dart` has been added to verify this behavior across all renderers.
Contributor
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a crash in Skwasm that occurred when attempting to transfer non-transferable texture sources. The change introduces a check to convert such sources to a transferable ImageBitmap before the transfer. The accompanying new test file effectively validates this fix. I've added one suggestion to refactor the new test file to improve its structure and maintainability by removing duplicated code.
Comment on lines
+19
to
+78
| Future<void> testMain() async { | ||
| setUpUnitTests(withImplicitView: true); | ||
|
|
||
| test('createImageFromTextureSource with HTMLImageElement and transferOwnership: true', () async { | ||
| final DomHTMLImageElement image = createDomHTMLImageElement(); | ||
| // Use a data URL to avoid network issues in tests | ||
| const transparentImage = | ||
| 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; | ||
| image.src = transparentImage; | ||
|
|
||
| final completer = Completer<void>(); | ||
| image.addEventListener( | ||
| 'load', | ||
| createDomEventListener((DomEvent event) { | ||
| completer.complete(); | ||
| }), | ||
| ); | ||
| await completer.future; | ||
|
|
||
| final ui.Image uiImage = await ui_web.createImageFromTextureSource( | ||
| image, | ||
| width: 1, | ||
| height: 1, | ||
| transferOwnership: true, | ||
| ); | ||
|
|
||
| expect(uiImage.width, 1); | ||
| expect(uiImage.height, 1); | ||
| uiImage.dispose(); | ||
| }); | ||
|
|
||
| test('createImageFromTextureSource with ImageBitmap and transferOwnership: true', () async { | ||
| final DomHTMLImageElement image = createDomHTMLImageElement(); | ||
| const transparentImage = | ||
| 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; | ||
| image.src = transparentImage; | ||
|
|
||
| final completer = Completer<void>(); | ||
| image.addEventListener( | ||
| 'load', | ||
| createDomEventListener((DomEvent event) { | ||
| completer.complete(); | ||
| }), | ||
| ); | ||
| await completer.future; | ||
|
|
||
| final DomImageBitmap bitmap = await createImageBitmap(image, (x: 0, y: 0, width: 1, height: 1)); | ||
|
|
||
| final ui.Image uiImage = await ui_web.createImageFromTextureSource( | ||
| bitmap, | ||
| width: 1, | ||
| height: 1, | ||
| transferOwnership: true, | ||
| ); | ||
|
|
||
| expect(uiImage.width, 1); | ||
| expect(uiImage.height, 1); | ||
| uiImage.dispose(); | ||
| }); | ||
| } |
Contributor
There was a problem hiding this comment.
To improve readability and reduce code duplication, you can extract the common setup logic for creating and loading the DomHTMLImageElement into a setUp block. This will make the tests more concise and easier to maintain.
Future<void> testMain() async {
setUpUnitTests(withImplicitView: true);
late DomHTMLImageElement image;
setUp(() async {
image = createDomHTMLImageElement();
// Use a data URL to avoid network issues in tests
const transparentImage =
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
image.src = transparentImage;
final completer = Completer<void>();
image.addEventListener(
'load',
createDomEventListener((DomEvent event) {
completer.complete();
}),
);
await completer.future;
});
test('createImageFromTextureSource with HTMLImageElement and transferOwnership: true', () async {
final ui.Image uiImage = await ui_web.createImageFromTextureSource(
image,
width: 1,
height: 1,
transferOwnership: true,
);
expect(uiImage.width, 1);
expect(uiImage.height, 1);
uiImage.dispose();
});
test('createImageFromTextureSource with ImageBitmap and transferOwnership: true', () async {
final DomImageBitmap bitmap = await createImageBitmap(image, (x: 0, y: 0, width: 1, height: 1));
final ui.Image uiImage = await ui_web.createImageFromTextureSource(
bitmap,
width: 1,
height: 1,
transferOwnership: true,
);
expect(uiImage.width, 1);
expect(uiImage.height, 1);
uiImage.dispose();
});
}
mdebbar
approved these changes
Mar 17, 2026
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Mar 18, 2026
…rable texture sources (flutter/flutter#183799)
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Mar 18, 2026
…rable texture sources (flutter/flutter#183799)
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Mar 18, 2026
…rable texture sources (flutter/flutter#183799)
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Mar 18, 2026
…rable texture sources (flutter/flutter#183799)
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Mar 18, 2026
…rable texture sources (flutter/flutter#183799)
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Mar 18, 2026
…rable texture sources (flutter/flutter#183799)
auto-submit bot
pushed a commit
to flutter/packages
that referenced
this pull request
Mar 19, 2026
flutter/flutter@d117642...dd64978 2026-03-18 [email protected] Roll Skia from 2fb5fa71eb12 to f0a13e5efbad (2 revisions) (flutter/flutter#183830) 2026-03-18 [email protected] Roll Skia from ae3d36cb9e29 to 2fb5fa71eb12 (3 revisions) (flutter/flutter#183823) 2026-03-18 [email protected] Linux reuse sibling (flutter/flutter#183653) 2026-03-18 [email protected] Roll Skia from 84a180a1fa80 to ae3d36cb9e29 (4 revisions) (flutter/flutter#183812) 2026-03-18 [email protected] fix(web): handle asynchronously disposed platform views (flutter/flutter#183666) 2026-03-17 [email protected] (Test cross-imports) Remove legacy Material import from sliver_constraints_test (flutter/flutter#183351) 2026-03-17 [email protected] Fix Android Studio pluginsPath when version is unknown (do not use 0.0) (flutter/flutter#182681) 2026-03-17 [email protected] Fixes animation glitch into bottom sheet (flutter/flutter#183303) 2026-03-17 [email protected] Handle#6537 second grouped test (flutter/flutter#182529) 2026-03-17 [email protected] Add a Clarification for the docs of suggestionsBuilder of SearchAnchor (flutter/flutter#183106) 2026-03-17 [email protected] Remove obsolete null checks from style guide (flutter/flutter#181703) 2026-03-17 [email protected] [Impeller] Do not delete the GL object in a HandleGLES if the handle has a cleanup callback (flutter/flutter#183561) 2026-03-17 [email protected] Encode source file patches as UTF-8 in the code formatter script (flutter/flutter#183761) 2026-03-17 [email protected] Fix widget inspector control layout and add safe area regression test (flutter/flutter#180789) 2026-03-17 [email protected] Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)" (flutter/flutter#182522) 2026-03-17 [email protected] fix(web): fix crash in Skwasm when transferring non-transferable texture sources (flutter/flutter#183799) 2026-03-17 [email protected] Roll Skia from dba893a44d7a to 84a180a1fa80 (7 revisions) (flutter/flutter#183803) 2026-03-17 [email protected] Framework: Improve DropdownButton selectedItemBuilder assertion (flutter/flutter#183732) 2026-03-17 [email protected] Add mainAxisAlignment to NavigationRail (flutter/flutter#183514) 2026-03-17 [email protected] Update android triage process to not look at unassigned p1s every week (flutter/flutter#183805) 2026-03-17 [email protected] Adds macos impeller new gallery transition perf test. (flutter/flutter#183802) 2026-03-17 [email protected] fix(web_ui): move prepareToDraw after raster to improve concurrency and stability (flutter/flutter#183791) 2026-03-17 [email protected] [build] Generate debug info for assembly. (flutter/flutter#183425) 2026-03-17 [email protected] [web] Fix occasional failure to find Chrome tab (flutter/flutter#183737) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The engine was previously attempting to transfer non-transferable objects like
HTMLImageElementto the web worker viapostMessagewhentransferOwnershipwas set totrue. This resulted in aDataCloneError.This change adds a check to see if the texture source is a transferable type when in multi-threaded mode. If not, it converts it to an
ImageBitmapusingcreateImageBitmapbefore transferring.A new test
test/ui/image_texture_source_test.darthas been added to verify this behavior across all renderers.Fixes #183166
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.