Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] GDI resource leaks when using the software renderer code path #107368

Closed
sevenstars opened this issue Jul 10, 2022 · 7 comments
Closed
Labels
c: performance Relates to speed or footprint issues (see "perf:" labels) engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-windows Building on or for Windows specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@sevenstars
Copy link

GDI resource (Device Context) leaks when using the software renderer code path.

This only happens when the app is using software rasterization, i.e., if the embedder explicitly specifies FlutterRendererType::kSoftware or AngleSurfaceManager::Create() somehow fails.

The leak happens in every frame, so after a while, number of leaks will soon reach the default per-process limit of GDI handles and then the app UI will not be responsive.

@sevenstars sevenstars added the from: performance template Issues created via a performance issue template label Jul 10, 2022
@darshankawar darshankawar removed the from: performance template Issues created via a performance issue template label Jul 11, 2022
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Jul 11, 2022
@danagbemava-nc
Copy link
Member

Hi @sevenstars, would it be possible for you to provide a complete minimal reproducible code sample as well as steps to reproduce?

Please also provide the output of flutter doctor -v.

Thank you

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 11, 2022
@sevenstars
Copy link
Author

Hi @sevenstars, would it be possible for you to provide a complete minimal reproducible code sample as well as steps to reproduce?

Please also provide the output of flutter doctor -v.

Thank you

The leak can be reproduced when the app is using software rasterization on Windows, i.e., in one of scenarios as follows:

  1. The embedder explicitly specifies kSoftware as the FlutterRendererType when calling embedder API FlutterEngineRun(), or
  2. AngleSurfaceManager::Create() somehow fails

I've created a PR to fix this: flutter/engine#34574

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 12, 2022
@danagbemava-nc
Copy link
Member

Hi @sevenstars, I'm not familiar with the scenarios you described above.

Can you provide a small sample app that has any of the scenarios described above?

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 12, 2022
@sevenstars
Copy link
Author

The leak can be reproduced with any flutter app using the software fallback path. The flutter engine will try to use hardware accelerated rendering if possible, and I found AngleSurfaceManager::Create() somehow fails on some Windows 7 machines, so in this case the flutter engine will use the software fallback path.

You can reproduce the leak on any Windows 10 machine, using the following steps:

  1. Use the DirectX Control Panel (DXCpl.exe) to apply Direct3D debug settings for the flutter app.
  2. Run the image_list example app.
  3. Use the GDIView tool to see the resource leaks.

The result:
After running the app for a few minutes, you will see the number of leaks reaches 10000, and the app will stop updating.

Use the DirectX Control Panel (DXCpl.exe) to apply Direct3D debug settings for the flutter app
ss_dxcpl_setting

Run the image_list example app
ss_flutter_run_output

Use the GDIView tool to see the resource leaks
ss_gdiview

cc @danagbemava-nc

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 13, 2022
@danagbemava-nc
Copy link
Member

danagbemava-nc commented Jul 13, 2022

Thanks for the repro info. I am unable to repro this at the moment so I will label for further insight and update when I am able to repro.

Sample for testing https://github.com/flutter/flutter/tree/master/examples/image_list

@danagbemava-nc danagbemava-nc added engine flutter/engine repository. See also e: labels. c: performance Relates to speed or footprint issues (see "perf:" labels) platform-windows Building on or for Windows specifically and removed in triage Presently being triaged by the triage team labels Jul 13, 2022
@loic-sharma
Copy link
Member

loic-sharma commented Jul 13, 2022

I was able to repro this by forcing the software renderer config on my local engine:

diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc
index ceb4634d43..c0065a6a78 100644
--- a/shell/platform/windows/flutter_windows_engine.cc
+++ b/shell/platform/windows/flutter_windows_engine.cc
@@ -305,9 +305,12 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) {
     args.custom_dart_entrypoint = entrypoint;
   }
 
-  FlutterRendererConfig renderer_config = surface_manager_
-                                              ? GetOpenGLRendererConfig()
-                                              : GetSoftwareRendererConfig();
+  // FlutterRendererConfig renderer_config = surface_manager_
+  //                                             ? GetOpenGLRendererConfig()
+  //                                             : GetSoftwareRendererConfig();
+
+
+  FlutterRendererConfig renderer_config = GetSoftwareRendererConfig();
 
   auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
                                   &args, this, &engine_);

@loic-sharma loic-sharma added the P2 Important issues not at the top of the work list label Jul 13, 2022
betrevisan pushed a commit to betrevisan/engine that referenced this issue Jul 15, 2022
…er#34574)

Updates `FlutterWindowWin32::OnBitmapSurfaceUpdated` to release the device context using `ReleaseDC`.

Fixes: flutter/flutter#107368
@danagbemava-nc danagbemava-nc added the r: fixed Issue is closed as already fixed in a newer version label Jul 18, 2022
@github-actions
Copy link

github-actions bot commented Aug 1, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: performance Relates to speed or footprint issues (see "perf:" labels) engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-windows Building on or for Windows specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

No branches or pull requests

4 participants