Repository navigation
The program for Windows runs only once #119415
Description
Activity
And in general, it works somehow strangely, if you close it and wait, the program may start, sometimes it may not. Or it may not start but be in processes, and the other instance will start normally, and there may be several instances in the process.
What's the output of
flutter doctor?What Windows version are you running?
Added a line of code for debugging in the release - file win32_window.cpp
MessageBox(NULL, L"Window ok", L"Title", MB_ICONINFORMATION);everything starts without problems, only before starting each time a window appears with a message
HWND window = CreateWindow(
window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
nullptr, nullptr, GetModuleHandle(nullptr), this);if (!window) {
return false;
}
MessageBox(NULL, L"Window ok", L"Title", MB_ICONINFORMATION);UpdateTheme(window);
return OnCreate();
}The flutter_window.cpp file does not always work
flutter_controller_->engine()->SetNextFrameCallback(& {
this->Show();
});I still don't understand why
if called simply
this->Show();
without using SetNextFrameCallback
then everything works- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Jan 30, 2023 Triage report
I can reproduce this issue on
Master (3.7.0-30.0.pre.7). Once you close the window, there still seems to be an open process in Task Manager. Manually ending the task doesn't solve the issue of the programming not opening again.flutter doctor -v(Master)[!] Flutter (Channel master, 3.7.0-30.0.pre.7, on Microsoft Windows [Version 10.0.22621.1105], locale en-US) • Flutter version 3.7.0-30.0.pre.7 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 15cd00f1ed (6 hours ago), 2023-01-29 21:58:05 -0500 • Engine revision a7bb0e4108 • Dart version 3.0.0 (build 3.0.0-179.0.dev) • DevTools version 2.20.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\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\213.7172.25.2113.9014738\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • 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.4.2) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.4.33122.133 • Windows 10 SDK version 10.0.22621.0 [✓] Android Studio (version 2021.3) • Android Studio at C:\Users\Nabeel\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\213.7172.25.2113.9014738 • Flutter plugin version 70.2.3 • Dart plugin version 213.7433 • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] VS Code (version 1.74.3) • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.46.0 [✓] VS Code (version 1.73.0-insider) • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code Insiders • Flutter extension version 3.50.0 [✓] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.1105] • Chrome (web) • chrome • web-javascript • unknown • Edge (web) • edge • web-javascript • Microsoft Edge 109.0.1518.52 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category.- addedengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallya: releaseChallenges faced when attempting to productionize an appChallenges faced when attempting to productionize an apphas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onfound in release: 3.7Found to occur in 3.7Found to occur in 3.7and removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Jan 30, 2023 When the program does not open, it is in the background tasks.
And if everything is fine, then in AppsI still don't understand why the program starts in different ways.
I'm seeing the same problem. The dead tasks are sitting in the message loop, waiting for something to happen.
17 remaining items
Thanks for tagging me, I'll investigate.
Mike is right: there's a race condition between the Windows main thread and Flutter's threads. Flutter can render the first frame before the main thread has a chance to register the callback that shows the window after the first frame.
I can reproduce this using a debugger:
- Add a breakpoint on
flutter::Shell::OnAnimatorDraw(that's when the Dart app renders something) - Add a breakpoint in
FlutterWindow::OnCreatewhere it sets the next frame callback - Run the app using the debugger
- When the
FlutterWindow::OnCreatebreakpoint is hit, freeze the main thread - Once the
flutter:Shell::OnAnimatorDrawbreakpoint has been hit twice, thaw the main thread
However, I haven't been able to reproduce this issue without a debugger. Do your apps have Windows plugins? Which ones? I suspect plugin initialization may be what's "slowing down" the main thread enough make it lose this race.
In any case, I'll work on a fix to remove this race condition.
Reacted by Yehuda Kremer- Add a breakpoint on
@loic-sharma you can use Windows 11 to create, build, and star the Flutter official demo called "counter". For example, you can create a project using the following command:
flutter create demo
Alternatively, you can use the binary program I packaged, which can be found at the following link:
https://github.com/AoEiuV020/FlutterDemo/releases/tag/3.7.7Many people have reported reproducing this issue.
It seems that the reproduction of this issue is tied to specific conditions. It may only occur on Windows 11 and specifically when running the binary program built with "flutter build". Additionally, it's worth noting that the official demo named "skeleton" does not exhibit this issue.
The specific behavior is that the first launch is normal, but subsequent launches may not display the foreground window.Reacted by Loïc SharmaThanks @AoEiuV020 for the link, I'm able to reproduce the issue with the app you shared! That'll help me verify the fix :)
- added a commit that references this issue
on May 24, 2023 Hello, the Windows app template was fixed on the
masterchannel by #127046. This fix will be available in the next non-hotfix Flutter release, likely Flutter 3.13 or higher.Apps created using Flutter 3.7 or 3.10 will need to be migrated after they've upgraded to Flutter 3.13 or the
masterchannel. This migration will be automatic if the Windows project has not been modified. If the Windows project has been modified, the following change can be applied to fix this bug:diff --git a/examples/hello_world/windows/runner/flutter_window.cpp b/examples/hello_world/windows/runner/flutter_window.cpp index f68aa9c26c0f5..7f66913a0293c 100644 --- a/examples/hello_world/windows/runner/flutter_window.cpp +++ b/examples/hello_world/windows/runner/flutter_window.cpp @@ -35,6 +35,11 @@ bool FlutterWindow::OnCreate() { this->Show(); }); + // Flutter can complete the first frame before the "show window" callback is + // registered. The following call ensures a frame is pending to ensure the + // window is shown. It is a no-op if the first frame hasn't completed yet. + flutter_controller_->ForceRedraw(); + return true; }
Warning
TheFlutterViewController::ForceRedrawAPI does not exist in Flutter 3.10. For now, you must switch to the themasterchannel to use this API. This API will be added in the next Flutter non-hotfix release, likely Flutter 3.13.Note
This migration will be done automatically if the Windows project has not been modified.If needed, you can use this temporary workaround while on Flutter 3.10. This workaround will no longer be necessary once you upgrade to Flutter 3.13 or higher.
I'll close this issue as it is now fixed. Please let me know if you have any questions!
- addedr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
on May 31, 2023 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 -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Jun 15, 2023



Hello
I decided to import the program for Windows, but a problem arose.
The same problem with a new project that I create from scratch.
For me, after the build, the project from the folder (exe file) is launched only the first time. It does not start the next time, but there are processes in the task manager.
exe debug file runs without problems. Created other projects from scratch, same problem.
I tried to run it on other computers, and there, too, only the first run, then everything. After renaming the folder, it starts again and also once.