Skip to content

[Impeller] Wait for the Vulkan device to become idle before destroying Vulkan objects in the AHBSwapchainImplVK destructor#187477

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
jason-simmons:bug_187237
Jun 4, 2026
Merged

[Impeller] Wait for the Vulkan device to become idle before destroying Vulkan objects in the AHBSwapchainImplVK destructor#187477
auto-submit[bot] merged 3 commits into
flutter:masterfrom
jason-simmons:bug_187237

Conversation

@jason-simmons

Copy link
Copy Markdown
Member

AHBSwapchainImplVK holds Vulkan objects such as fences that may be used by operations submitted to the Vulkan device. The AHBSwapchainImplVK destructor must wait until the device is no longer using these objects before destroying them.

Fixes #187237

…g Vulkan objects in the AHBSwapchainImplVK destructor

AHBSwapchainImplVK holds Vulkan objects such as fences that may be used
by operations submitted to the Vulkan device.  The
AHBSwapchainImplVK destructor must wait until the device is no longer
using these objects before destroying them.

Fixes flutter#187237
@jason-simmons jason-simmons requested a review from gaaclarke June 2, 2026 23:36
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 2, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Jun 2, 2026

@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 AHBSwapchainImplVK destructor to call a new WaitIdle helper method, ensuring the Vulkan device is idle before destroying objects, and adds a corresponding unit test. Review feedback suggests simplifying the class interface by inlining the WaitIdle logic directly into the destructor and removing the helper method. Additionally, it is recommended to use const auto instead of auto const in the test file to align with the repository's C++ style conventions.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 2, 2026
@jason-simmons jason-simmons added the CICD Run CI/CD label Jun 3, 2026
gaaclarke
gaaclarke previously approved these changes Jun 3, 2026
Comment on lines +130 to +131
[[maybe_unused]] auto result =
ContextVK::Cast(*context).GetDevice().waitIdle();

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.

Is this gobbling up an error code that maybe we'd want to surface in debug builds?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The convention elsewhere in the Vulkan back end has been to ignore results that are not actionable (see KHRSwapchainImplVK::WaitIdle and ~ContextVK.

I suppose we can add an FML_LOG here just in case.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 3, 2026
@jason-simmons jason-simmons added the CICD Run CI/CD label Jun 3, 2026
@jason-simmons jason-simmons requested a review from gaaclarke June 3, 2026 19:12

@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

@jason-simmons jason-simmons added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 4, 2026
@auto-submit

auto-submit Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/187477, because - The status or check suite Mac_arm64 run_debug_test_macos has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 4, 2026
@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 4, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 4, 2026
Merged via the queue into flutter:master with commit 1454754 Jun 4, 2026
211 of 212 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 4, 2026
@FelixMittermeier

Copy link
Copy Markdown

I can confirm that this fixed the issue. Thanks a lot for your great work 🙏

auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 5, 2026
Roll Flutter from 2ba5420a7049 to 1bdf4af29076 (43 revisions)

flutter/flutter@2ba5420...1bdf4af

2026-06-05 engine-flutter-autoroll@skia.org Roll Packages from 03352b5 to 61bdbb4 (5 revisions) (flutter/flutter#187612)
2026-06-05 engine-flutter-autoroll@skia.org Roll Skia from 6e003d7f69c8 to a47a9a2c8ae5 (1 revision) (flutter/flutter#187610)
2026-06-05 engine-flutter-autoroll@skia.org Roll Dart SDK from aad8be4ce307 to 6a9a0efe66eb (10 revisions) (flutter/flutter#187609)
2026-06-05 engine-flutter-autoroll@skia.org Roll Skia from 494f1bf55f51 to 6e003d7f69c8 (2 revisions) (flutter/flutter#187607)
2026-06-05 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from ZE1Jy9CtVVi-tjBAE... to N_LiSaBSUsE2LDZgG... (flutter/flutter#187597)
2026-06-05 engine-flutter-autoroll@skia.org Roll Skia from 59556fdb8c33 to 494f1bf55f51 (2 revisions) (flutter/flutter#187596)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 8eb107046fd5 to 59556fdb8c33 (1 revision) (flutter/flutter#187590)
2026-06-04 34871572+gmackall@users.noreply.github.com Remove `embedded_android_views_integration_test.dart` (flutter/flutter#187465)
2026-06-04 burak.karahan@mail.ru Remove Material imports from rendering editable tests (flutter/flutter#186951)
2026-06-04 jason-simmons@users.noreply.github.com [Impeller] Wait for the Vulkan device to become idle before destroying Vulkan objects in the AHBSwapchainImplVK destructor (flutter/flutter#187477)
2026-06-04 chris@bracken.jp [iOS] Eliminate unnecessary redeclaration of FlutterDisplayLink (flutter/flutter#187557)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 928ded2a31af to 8eb107046fd5 (1 revision) (flutter/flutter#187583)
2026-06-04 34871572+gmackall@users.noreply.github.com Log stdout in adb.dart (flutter/flutter#187531)
2026-06-04 mvincentong@gmail.com Clarify RouterDelegate popRoute bubbling (flutter/flutter#186875)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 928ded2a31af to 8eb107046fd5 (1 revision) (flutter/flutter#187584)
2026-06-04 1063596+reidbaker@users.noreply.github.com Add updating-android-sdk agent skill for rolling Android SDK in CIPD (flutter/flutter#187576)
2026-06-04 Rusino@users.noreply.github.com Fixing alignment issue (flutter/flutter#187518)
2026-06-04 brackenavaron@gmail.com [Material Cross Imports] Clean up Material Divider usages (flutter/flutter#187300)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from cecc0e0da9ae to 928ded2a31af (6 revisions) (flutter/flutter#187574)
2026-06-04 31859944+LongCatIsLooong@users.noreply.github.com Use swift demangle to verify internal Swift symbols (flutter/flutter#186835)
2026-06-04 1063596+reidbaker@users.noreply.github.com Add android 37 platform and build tools to script for android cipd bundle creation (flutter/flutter#187571)
2026-06-04 jason-simmons@users.noreply.github.com [Impeller] Increase the precision of the IPSampleWithTileModeOES coords parameter to match the input coordinates in the tiled_texture_fill_external shader (flutter/flutter#187545)
2026-06-04 engine-flutter-autoroll@skia.org Roll Packages from b11504f to 03352b5 (4 revisions) (flutter/flutter#187569)
2026-06-04 iinozemtsev@google.com Roll Dart SDK to Dart 3.13 beta2 (flutter/flutter#187555)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 611e3f8ceb93 to cecc0e0da9ae (1 revision) (flutter/flutter#187562)
2026-06-04 6655696+guidezpl@users.noreply.github.com Add step to bootstrap Flutter tool in coverage workflow (flutter/flutter#187199)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 4fdb859c8da7 to 611e3f8ceb93 (4 revisions) (flutter/flutter#187554)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 0020aae33f63 to 4fdb859c8da7 (2 revisions) (flutter/flutter#187552)
2026-06-04 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from ap7MhLX4TdpWRrLS_... to ZE1Jy9CtVVi-tjBAE... (flutter/flutter#187550)
2026-06-04 stuartmorgan@google.com Add vector_math to package issue template (flutter/flutter#187536)
2026-06-04 jason-simmons@users.noreply.github.com Manual roll Dart SDK from d39850bf4a01 to 3b70b98fa7c0 (flutter/flutter#187519)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from d625048c853a to 0020aae33f63 (20 revisions) (flutter/flutter#187539)
2026-06-04 smille2003@yandex.ru [Impeller][Windows] fix black screen on OpenGL fallback (flutter/flutter#187288)
2026-06-04 97480502+b-luk@users.noreply.github.com Fix unintentionally joined path contours (flutter/flutter#187522)
2026-06-03 matt.boetger@gmail.com fix: resolve issue #177379 by using lazy buildDirectory.dir() API in build.gradle template (flutter/flutter#187127)
2026-06-03 34871572+gmackall@users.noreply.github.com Add a skill for flake analysis (flutter/flutter#187530)
2026-06-03 30870216+gaaclarke@users.noreply.github.com adds linux impeller project flag (flutter/flutter#186982)
2026-06-03 codedoctor@linwood.dev Add support for stylus buttons (flutter/flutter#183369)
2026-06-03 46920873+gabrimatic@users.noreply.github.com Prevent Cubic transform from looping on out-of-range input (flutter/flutter#185875)
2026-06-03 bdero@google.com [Impeller] Reland: Allow attaching specific texture mip levels and slices (flutter/flutter#187470)
2026-06-03 kjlubick@users.noreply.github.com [skia] Update image deserial proc (flutter/flutter#185041)
2026-06-03 112751483+shivanshu877@users.noreply.github.com docs: update Impeller advanced blend docs for framebuffer fetch (flutter/flutter#185457)
2026-06-03 ahmedsameha1@gmail.com Handle#6537 fifth grouped tests (flutter/flutter#183720)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
...
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11849)

Roll Flutter from 2ba5420a7049 to 1bdf4af29076 (43 revisions)

flutter/flutter@2ba5420...1bdf4af

2026-06-05 engine-flutter-autoroll@skia.org Roll Packages from 03352b5 to 61bdbb4 (5 revisions) (flutter/flutter#187612)
2026-06-05 engine-flutter-autoroll@skia.org Roll Skia from 6e003d7f69c8 to a47a9a2c8ae5 (1 revision) (flutter/flutter#187610)
2026-06-05 engine-flutter-autoroll@skia.org Roll Dart SDK from aad8be4ce307 to 6a9a0efe66eb (10 revisions) (flutter/flutter#187609)
2026-06-05 engine-flutter-autoroll@skia.org Roll Skia from 494f1bf55f51 to 6e003d7f69c8 (2 revisions) (flutter/flutter#187607)
2026-06-05 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from ZE1Jy9CtVVi-tjBAE... to N_LiSaBSUsE2LDZgG... (flutter/flutter#187597)
2026-06-05 engine-flutter-autoroll@skia.org Roll Skia from 59556fdb8c33 to 494f1bf55f51 (2 revisions) (flutter/flutter#187596)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 8eb107046fd5 to 59556fdb8c33 (1 revision) (flutter/flutter#187590)
2026-06-04 34871572+gmackall@users.noreply.github.com Remove `embedded_android_views_integration_test.dart` (flutter/flutter#187465)
2026-06-04 burak.karahan@mail.ru Remove Material imports from rendering editable tests (flutter/flutter#186951)
2026-06-04 jason-simmons@users.noreply.github.com [Impeller] Wait for the Vulkan device to become idle before destroying Vulkan objects in the AHBSwapchainImplVK destructor (flutter/flutter#187477)
2026-06-04 chris@bracken.jp [iOS] Eliminate unnecessary redeclaration of FlutterDisplayLink (flutter/flutter#187557)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 928ded2a31af to 8eb107046fd5 (1 revision) (flutter/flutter#187583)
2026-06-04 34871572+gmackall@users.noreply.github.com Log stdout in adb.dart (flutter/flutter#187531)
2026-06-04 mvincentong@gmail.com Clarify RouterDelegate popRoute bubbling (flutter/flutter#186875)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 928ded2a31af to 8eb107046fd5 (1 revision) (flutter/flutter#187584)
2026-06-04 1063596+reidbaker@users.noreply.github.com Add updating-android-sdk agent skill for rolling Android SDK in CIPD (flutter/flutter#187576)
2026-06-04 Rusino@users.noreply.github.com Fixing alignment issue (flutter/flutter#187518)
2026-06-04 brackenavaron@gmail.com [Material Cross Imports] Clean up Material Divider usages (flutter/flutter#187300)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from cecc0e0da9ae to 928ded2a31af (6 revisions) (flutter/flutter#187574)
2026-06-04 31859944+LongCatIsLooong@users.noreply.github.com Use swift demangle to verify internal Swift symbols (flutter/flutter#186835)
2026-06-04 1063596+reidbaker@users.noreply.github.com Add android 37 platform and build tools to script for android cipd bundle creation (flutter/flutter#187571)
2026-06-04 jason-simmons@users.noreply.github.com [Impeller] Increase the precision of the IPSampleWithTileModeOES coords parameter to match the input coordinates in the tiled_texture_fill_external shader (flutter/flutter#187545)
2026-06-04 engine-flutter-autoroll@skia.org Roll Packages from b11504f to 03352b5 (4 revisions) (flutter/flutter#187569)
2026-06-04 iinozemtsev@google.com Roll Dart SDK to Dart 3.13 beta2 (flutter/flutter#187555)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 611e3f8ceb93 to cecc0e0da9ae (1 revision) (flutter/flutter#187562)
2026-06-04 6655696+guidezpl@users.noreply.github.com Add step to bootstrap Flutter tool in coverage workflow (flutter/flutter#187199)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 4fdb859c8da7 to 611e3f8ceb93 (4 revisions) (flutter/flutter#187554)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from 0020aae33f63 to 4fdb859c8da7 (2 revisions) (flutter/flutter#187552)
2026-06-04 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from ap7MhLX4TdpWRrLS_... to ZE1Jy9CtVVi-tjBAE... (flutter/flutter#187550)
2026-06-04 stuartmorgan@google.com Add vector_math to package issue template (flutter/flutter#187536)
2026-06-04 jason-simmons@users.noreply.github.com Manual roll Dart SDK from d39850bf4a01 to 3b70b98fa7c0 (flutter/flutter#187519)
2026-06-04 engine-flutter-autoroll@skia.org Roll Skia from d625048c853a to 0020aae33f63 (20 revisions) (flutter/flutter#187539)
2026-06-04 smille2003@yandex.ru [Impeller][Windows] fix black screen on OpenGL fallback (flutter/flutter#187288)
2026-06-04 97480502+b-luk@users.noreply.github.com Fix unintentionally joined path contours (flutter/flutter#187522)
2026-06-03 matt.boetger@gmail.com fix: resolve issue #177379 by using lazy buildDirectory.dir() API in build.gradle template (flutter/flutter#187127)
2026-06-03 34871572+gmackall@users.noreply.github.com Add a skill for flake analysis (flutter/flutter#187530)
2026-06-03 30870216+gaaclarke@users.noreply.github.com adds linux impeller project flag (flutter/flutter#186982)
2026-06-03 codedoctor@linwood.dev Add support for stylus buttons (flutter/flutter#183369)
2026-06-03 46920873+gabrimatic@users.noreply.github.com Prevent Cubic transform from looping on out-of-range input (flutter/flutter#185875)
2026-06-03 bdero@google.com [Impeller] Reland: Allow attaching specific texture mip levels and slices (flutter/flutter#187470)
2026-06-03 kjlubick@users.noreply.github.com [skia] Update image deserial proc (flutter/flutter#185041)
2026-06-03 112751483+shivanshu877@users.noreply.github.com docs: update Impeller advanced blend docs for framebuffer fetch (flutter/flutter#185457)
2026-06-03 ahmedsameha1@gmail.com Handle#6537 fifth grouped tests (flutter/flutter#183720)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
...
@Rong-Good

Copy link
Copy Markdown

Hi team,

Thank you for fixing #187237 — we've verified the fix on master and would like to request a cherry-pick to stable for an upcoming 3.44.x hotfix.


Environment

  • Flutter (affected): stable 3.44.3 (Engine a4ce257c68)
  • Flutter (fixed): master 3.45.0-pre (Engine d5142abed8)
  • Device: Redmi evergo, Android 13 (TP1A.220624.014), arm64-v8a
  • GPU: Mali (libGLES_mali.so)
  • Rendering: Impeller (Vulkan) — default on Android

App context

Live-streaming app, live detail page with an embedded video player (PlatformView, TextureView via AliPlayer SDK). Fullscreen is implemented via SystemChrome.setPreferredOrientations (portrait ↔ landscape).


Reproduction steps

  1. Open live detail page with video playing
  2. Tap fullscreen (landscape)
  3. Exit fullscreen (portrait)
  4. Repeat steps 2–3 quickly, ~10–20 times
  5. Result on stable 3.44.3: intermittent crash (reproducible after several toggles)

Crash signature (stable 3.44.3)

signal 6 (SIGABRT)
Abort message: 'FORTIFY: pthread_mutex_lock called on a destroyed mutex'
Thread: mali-cmar-backe
Backtrace:
  #03 pthread_mutex_lock
  #04 libGLES_mali.so
  #05 libGLES_mali.so
  #06 libGLES_mali.so

Logcat also shows:

Using the Impeller rendering backend (Vulkan).

Verification

  • stable 3.44.3 — crash reproduces after repeated fullscreen toggles
  • stable 3.41.9 — same vulnerable code path (~AHBSwapchainImplVK() = default)
  • master (3.45.0-pre) — same repro steps, no crash after many toggles

Engine source check:

  • stable: AHBSwapchainImplVK::~AHBSwapchainImplVK() = default;
  • master: destructor calls WaitIdle() (this PR)

Impact

Affects production apps on stable using Impeller (default on Android) + Mali GPU devices (Xiaomi/Redmi, Samsung, etc.) + orientation/surface size changes (fullscreen video, rotation).

EnableImpeller=false works as a workaround, but we'd prefer the proper engine fix on stable.


Request

Could this fix please be cherry-picked to stable (flutter-3.44-candidate.0) for a 3.44.4+ hotfix?

Most production teams cannot ship on master pre-releases. This is a native crash (SIGABRT), not catchable in Dart.

Happy to re-test a CP build on our Redmi device. Thanks again for the fix!

@FelixMittermeier

Copy link
Copy Markdown

I am also surprised that this fix has not yet been considered for a cherry-pick to stable. Without this change, apps on devices with Mali GPUs crash so often that users are starting to get frustrated.

Therefore, I support the request from @Rong-Good

@jason-simmons jason-simmons added cp: stable cherry pick this pull request to stable release candidate branch cp: beta cherry pick this pull request to beta release candidate branch labels Jun 24, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

@walley892 walley892 added cp: beta cherry pick this pull request to beta release candidate branch and removed cp: beta cherry pick this pull request to beta release candidate branch labels Jun 25, 2026
auto-submit Bot pushed a commit that referenced this pull request Jun 26, 2026
… destroying Vulkan objects in the AHBSwapchainImplVK destructor (#187477) (#188588)

### Issue Link:

#187237

### Impact Description:

This can cause a crash on Impeller/Vulkan during app lifecycle events (shutdown/rotation/etc.) when using HCPP/AHBSwapchain.

### Changelog Description:

[flutter/187237] Fixes a crash that can happen during app shutdown or rotation on some Android devices using Impeller/Vulkan with HCPP.

### Workaround:

Disable Impeller or use the Impeller GLES back end

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:

Run the `AndroidAHBSwapchainTest.AHBSwapchainDtorCallsWaitIdle` unit test.  Or try reproducing the crash in the #187237 example app and verifying that it is fixed.
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…g Vulkan objects in the AHBSwapchainImplVK destructor (flutter#187477)

AHBSwapchainImplVK holds Vulkan objects such as fences that may be used
by operations submitted to the Vulkan device. The AHBSwapchainImplVK
destructor must wait until the device is no longer using these objects
before destroying them.

Fixes flutter#187237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: beta cherry pick this pull request to beta release candidate branch cp: stable cherry pick this pull request to stable release candidate branch e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android Impeller/Vulkan crash on Mali GPU when rotating during startup

6 participants