From 1f0f5b45036155e5e1a9c291e8c5f2bedbc34d9d Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Mon, 21 Sep 2026 19:18:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(windows):=20=E5=85=A8=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=BD=AF=E4=BB=B6=E6=B8=B2=E6=9F=93=E2=80=94?= =?UTF-8?q?=E2=80=94=E6=A0=B9=E6=B2=BB=E5=A4=9A=E6=9C=BA=E7=99=BD=E5=B1=8F?= =?UTF-8?q?=EF=BC=88RDP/=E8=80=81=E6=98=BE=E5=8D=A1/=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E5=B7=AE=E5=BC=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户实测三台电脑(Win10×2/Win11×1)安装后白屏,远程与非远程均有;进程与 HTTP 服务完全健康(manifest 可访问、cmd 无报错)——纯渲染层失败。属于 Flutter Windows 引擎 GPU/ANGLE 渲染在真实环境的已知兼容性问题 (flutter/flutter#74856:RDP 会话 OpenGL 不可用白屏;老/虚拟显卡同理)。 方案:wWinMain 入口(引擎创建前)设置 FLUTTER_ENGINE_SWITCHES= --enable-software-rendering,全部环境统一软件渲染。本应用为轻量状态页 (列表/卡片/图标),软件渲染性能无感;换来 RDP、老显卡、驱动缺失等 一切图形环境可用。此前 ANGLE_PLATFORM_BACKEND=d3d9 试验失败(Flutter 自带的 ANGLE 仅含 d3d11 后端),软件渲染是为该场景设计的官方开关。 --- windows/runner/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index 020729f..f2fb8c8 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -7,6 +7,12 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { + // 统一软件渲染:Flutter 的 GPU/ANGLE 渲染在多种真实环境下初始化失败导致 + // 白屏窗口(RDP 远程会话、老显卡/驱动、虚拟显卡——实测远程与非远程机器 + // 均有白屏,而进程与 HTTP 服务本身健康)。本应用界面为轻量状态页,软件 + // 渲染性能足够;引擎开关必须在引擎创建前经 FLUTTER_ENGINE_SWITCHES 注入。 + SetEnvironmentVariable(L"FLUTTER_ENGINE_SWITCHES", L"--enable-software-rendering"); + // Attach to console when present (e.g., 'flutter run') or create a // new console when running with a debugger. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {