flutter icon indicating copy to clipboard operation
flutter copied to clipboard

App freezes when GPU is disabled while the app is running

Open temirlanzhangazy opened this issue 3 years ago • 23 comments

While running Flutter app on a desktop, if you disable GPU, (even if enable it again) flutter app will freeze.

Expected results: Flutter Desktop App would switch GPU or turn on software rendering.

Actual results: Rendering has stopped. The application is frozen.

Example: Windows app built with Flutter is set to launch on startup, but some users are experiencing issues where their GPU is not fully enabled yet, causing the app to freeze or crash. To address this, a third-party app was developed that delays the launch of the Flutter app until the GPU is fully enabled. Also when some GPU functionalities like Nvidia G-Sync were turned on AFTER the flutter app was launched, app freezes too.

flutter doctor -v
[√] Flutter (Channel master, 3.9.0-13.0.pre.4, on Microsoft Windows [Version 10.0.19045.2728], locale
    en-GB)
    • Flutter version 3.9.0-13.0.pre.4 on channel master at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8de2433a4c (2 weeks ago), 2023-03-21 06:58:24 -0400
    • Engine revision e07fb9b5dd
    • Dart version 3.0.0 (build 3.0.0-348.0.dev)
    • DevTools version 2.22.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\zhang\AppData\Local\Android\sdk
    • Platform android-33-ext5, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at
    .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.5.33516.290
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)

[√] VS Code (version 1.76.2)
    • VS Code at C:\Users\zhang\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.62.0

[√] Connected device (2 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.2728]
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 111.0.1661.62

[√] Network resources
    • All expected network resources are available.

temirlanzhangazy avatar Apr 05 '23 10:04 temirlanzhangazy

Hello @temirlanzhangazy. Are you able to reproduce this issue in debug mode? Are there any stack traces you can provide?

exaby73 avatar Apr 05 '23 12:04 exaby73

Hello. I tried the same thing in debug mode: same result. What is interesting: The app seems to be fully working, all print messages are being created, and Windows cursor is reacting to hover events (pointer cursor on button).

temirlanzhangazy avatar Apr 06 '23 07:04 temirlanzhangazy

Hi @temirlanzhangazy, does this occur with the sample app as well or only with your app?

danagbemava-nc avatar Apr 06 '23 07:04 danagbemava-nc

Yes, this occurs with the sample app too.

temirlanzhangazy avatar Apr 06 '23 07:04 temirlanzhangazy

https://user-images.githubusercontent.com/61193731/230309408-7bcc83c6-2d84-4e88-812d-84eb950f1c8b.mp4

Here is the sample app. When I disable the GPU driver, all apps will switch GPU or turn on software rendering. But flutter app's rendering is freezed.

temirlanzhangazy avatar Apr 06 '23 07:04 temirlanzhangazy

Hi @temirlanzhangazy, if you run the app with the --enable-software-rendering flag, do you still have this issue? Can you also check on the latest version of the master channel to see if the issue is still there?

danagbemava-nc avatar Apr 06 '23 13:04 danagbemava-nc

Yes, issue is the same with --enable-software-rendering flag. I have the latest version of the master channel.

I noticed these errors after disabling GPU. 2 ERR: SwapChain11.cpp:947 (present): Present failed: the D3D11 device was removed, HRESULT: 0x887A0005 2142 [ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(217)] Could not make the context current to acquire the frame.

temirlanzhangazy avatar Apr 06 '23 13:04 temirlanzhangazy

How can I catch these errors so I can exit my application?

temirlanzhangazy avatar Apr 06 '23 18:04 temirlanzhangazy

The error looks to be coming from the engine and not from the framework, so I don't think there is a way to catch these errors. I have a Windows laptop with a dedicated, as well as iGPU, but currently I do not have it with me. I'll try to reproduce this issue with the steps I can see in the video you provided in https://github.com/flutter/flutter/issues/124194#issuecomment-1498632861 and get back here with my findings

exaby73 avatar Apr 10 '23 13:04 exaby73

I can reproduce this issue on Windows 11 on Master (3.10.0-3.0.pre.30). I disabled the iGPU via device manager to reproduce this. I got the same error logs as OP in this instance. Disabling external GPU does not reproduce this.

ERR: SwapChain11.cpp:947 (present): Present failed: the D3D11 device was removed, HRESULT: 0x887A0005
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(217)] Could not make the context current to acquire the frame.
flutter doctor -v (Master)
[!] Flutter (Channel master, 3.10.0-3.0.pre.30, on Microsoft Windows [Version 10.0.22621.1485], locale en-IN)
    • Flutter version 3.10.0-3.0.pre.30 on channel master at C:\Users\Nabeel\fvm\versions\master
    ! The flutter binary is not on your path. Consider adding C:\Users\Nabeel\fvm\versions\master\bin to your path.
    ! Warning: `dart` on your path resolves to C:\tools\dart-sdk\bin\dart.exe, which is not inside your current Flutter SDK checkout at C:\Users\Nabeel\fvm\versions\master. Consider adding C:\Users\Nabeel\fvm\versions\master\bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2cf8502589 (3 hours ago), 2023-04-10 20:21:24 -0700
    • Engine revision 4a7f3f2a1f
    • Dart version 3.0.0 (build 3.0.0-427.0.dev)
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\android-sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Users\Nabeel\programs\android-studio-preview\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9746777)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.0)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.5.33414.496
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2022.1)
    • Android Studio at C:\Users\Nabeel\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\221.6008.13.2211.9619390
    • Flutter plugin version 72.1.2
    • Dart plugin version 221.6103.1
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)

[✓] Android Studio (version 2022.3)
    • Android Studio at C:\Users\Nabeel\programs\android-studio-preview
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9746777)

[✓] VS Code (version 1.77.0)
    • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.46.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.1485]
    • Chrome (web)      • chrome  • web-javascript • unknown
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 112.0.1722.34

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

exaby73 avatar Apr 11 '23 06:04 exaby73

Thank you for reporting this issue!

The Flutter engine accepts render configs at startup and does not support switching between GPU/software rendering at runtime yet.

Windows app built with Flutter is set to launch on startup, but some users are experiencing issues where their GPU is not fully enabled yet, causing the app to freeze or crash

This is surprising. I would expect this to work using software rendering. We might need to update our GPU detection logic to better handle this startup scenario.

Also when some GPU functionalities like Nvidia G-Sync were turned on AFTER the flutter app was launched, app freezes too.

I'm not familiar with this. This sounds like a bug that we'll need to investigate.

loic-sharma avatar Apr 11 '23 21:04 loic-sharma

It seems this issue also happens if you update your drivers while a Flutter app is running: https://github.com/flutter/flutter/issues/88007

loic-sharma avatar Apr 12 '23 18:04 loic-sharma

I've also seen this on customer devices: When putting a machine to sleep while a Flutter app is running and waking it up afterwards, the app sometimes hangs. A debug build revealed that those devices had lost the context ("Could not make the context current to acquire the frame").

AngleSurfaceManager::MakeCurrent (see https://github.com/flutter/engine/blob/360ca05311c8fafe73333ca2c58dfecf9b701d40/shell/platform/windows/angle_surface_manager.cc#L277) should recreate the context if eglMakeCurrent() returns EGL_FALSE and eglGetError() == EGL_CONTEXT_LOST

Related: https://github.com/flutter/flutter/issues/111151

jnschulze avatar Apr 17 '23 07:04 jnschulze

ERR: SwapChain11.cpp:947 (present): Present failed: the D3D11 device was removed, HRESULT: 0x00000000
ERR: SwapChain11.cpp:947 (present): Present failed: the D3D11 device was removed, HRESULT: 0x00000000
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
flutter: Saving frame: null: 799.0/600.0, offset:2525.0/102.0, isMaximized:false, isFullscreen:false
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(218)] Could not make the context current to acquire the frame.
Lost connection to device.

21pages avatar Jan 21 '24 06:01 21pages

Just wanted to chime in and add another user to the pile. I believe I've been experiencing this same issue, predominately when windows restores from a sleep state. I've noted the cursor still responds to click targets and the app is still functioning underneath however the UI is completely frozen. Resizing the window leaves blank space.

I've not experienced this in my development environment with a AMD GPU, only production, which runs on Intel integrated graphics. This has a significant effect on my applications viability as at current there is no way to appropriately handle the bug.

Edit 19/4/24: I added a wakelock to my app to see if that has any effect on the renderer crashing. It does not seem to prevent anything, it still sporadically breaks with the app still running underneath leaving the user to manually restart the app.

jonodav avatar Mar 27 '24 00:03 jonodav

Is there any update for this 😭

annd22 avatar Apr 24 '24 09:04 annd22

The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

flutter-triage-bot[bot] avatar Jun 06 '24 23:06 flutter-triage-bot[bot]

Is there any update for this?Like how I can catch this error in dart or native code then I can exit my app. 😭😭

MU-XICHEN avatar Jun 18 '24 13:06 MU-XICHEN

Is there any update for this?Like how I can catch this error in dart or native code then I can exit my app. 😭😭

I found a temp solution: The app freezes and these logs apprear whenever the Display event (with EventId = 4101) catched by the system, you can check it with the Event Viewer app. So I just simply write the function in windows native file (.cpp) to catch the Display event (using EvtSubscribe), then show a simple dialog (using MessageBox) to inform to the user that the rendering device has been lost, and the application is closing. I see that the Overwatch game is doing this way so I think it the valid solution, at least you can tell the user what happening instead of freezing the whole app without any information.

annd22 avatar Jun 18 '24 15:06 annd22

Is there any update for this?Like how I can catch this error in dart or native code then I can exit my app. 😭😭↳

I found a temp solution: The app freezes and these logs apprear whenever the Display event (with EventId = 4101) catched by the system, you can check it with the Event Viewer app. So I just simply write the function in windows native file (.cpp) to catch the Display event (using EvtSubscribe), then show a simple dialog (using MessageBox) to inform to the user that the rendering device has been lost, and the application is closing. I see that the Overwatch game is doing this way so I think it the valid solution, at least you can tell the user what happening instead of freezing the whole app without any information.↳

Really? I appriciate for that, sounds like a valid work, I will try it first. Besides ,where I can get the info about the game using this method, I want to learn some of it, thank you very much

MU-XICHEN avatar Jun 19 '24 06:06 MU-XICHEN