Skip to content

fix(windows): destroy window before quitting message loop - #590

Open
Davit-Meliqyan wants to merge 2 commits into
leanflutter:mainfrom
Davit-Meliqyan:fix/windows-destroy-shutdown
Open

fix(windows): destroy window before quitting message loop#590
Davit-Meliqyan wants to merge 2 commits into
leanflutter:mainfrom
Davit-Meliqyan:fix/windows-destroy-shutdown

Conversation

@Davit-Meliqyan

Copy link
Copy Markdown

Summary

Fixes a Windows shutdown delay when setPreventClose(true) is enabled.

Problem

windowManager.destroy() currently calls:

PostQuitMessage(0);

This exits the Win32 message loop before the native window is actually destroyed.

As a result, Flutter Engine shutdown happens outside the normal window lifecycle and the process may remain alive for around 17–18 seconds before exiting.

Solution

Replace:

PostQuitMessage(0);

with:

HWND hWnd = GetMainWindow();
is_prevent_close_ = false;
DestroyWindow(hWnd);

This restores the normal Win32 shutdown sequence:

WM_CLOSE
→ DestroyWindow
→ WM_DESTROY
→ FlutterWindow::OnDestroy()
→ Flutter Engine shutdown
→ PostQuitMessage

Verification

Tested on Windows 11.

Before:

  • Closing the application with setPreventClose(true) caused a ~17–18 second delay before process exit.

After:

  • Application exits immediately in both Debug and Release builds.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant