Skip to content

Fix the issue on macOS where, after a hot restart with multiple windows, unresponsive windows are left behind.#180287

Merged
knopp merged 2 commits intoflutter:masterfrom
yiiim:multiple_window_macos_fix
Jan 28, 2026
Merged

Fix the issue on macOS where, after a hot restart with multiple windows, unresponsive windows are left behind.#180287
knopp merged 2 commits intoflutter:masterfrom
yiiim:multiple_window_macos_fix

Conversation

@yiiim
Copy link
Member

@yiiim yiiim commented Dec 25, 2025

There is currently an issue with multiple windows on macOS: after a hot restart, new windows are created, but the original windows are not closed. You can reproduce this by running examples/multiple_windows and then performing a hot restart.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions bot added engine flutter/engine related. See also e: labels. a: desktop Running on desktop platform-macos labels Dec 25, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue on macOS where windows were not being closed after a hot restart in multi-window mode. The fix involves calling closeAllWindows on the FlutterWindowController during the onPreEngineRestart engine callback. The closeAllWindows method has been moved from a testing-only category to the main interface to allow this. A new test case has been added to verify that multiple windows are correctly closed. The changes look correct and effectively solve the described problem.

Comment on lines +220 to +241
int64_t handle1 = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
int64_t handle2 = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
int64_t handle3 = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);

// Verify windows are created
FlutterViewController* viewController1 = [engine viewControllerForIdentifier:handle1];
FlutterViewController* viewController2 = [engine viewControllerForIdentifier:handle2];
FlutterViewController* viewController3 = [engine viewControllerForIdentifier:handle3];
EXPECT_NE(viewController1, nil);
EXPECT_NE(viewController2, nil);
EXPECT_NE(viewController3, nil);

// Close all windows
[engine.windowController closeAllWindows];

// Verify all windows are closed and view controllers are disposed
viewController1 = [engine viewControllerForIdentifier:handle1];
viewController2 = [engine viewControllerForIdentifier:handle2];
viewController3 = [engine viewControllerForIdentifier:handle3];
EXPECT_EQ(viewController1, nil);
EXPECT_EQ(viewController2, nil);
EXPECT_EQ(viewController3, nil);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve the test's readability and maintainability, you could refactor it to use a loop for creating and verifying the windows. This avoids repetition and makes it easier to adjust the number of windows being tested.

  const int kWindowCount = 3;
  int64_t handles[kWindowCount];
  for (int i = 0; i < kWindowCount; ++i) {
    handles[i] = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
  }

  // Verify windows are created
  for (int i = 0; i < kWindowCount; ++i) {
    EXPECT_NE([engine viewControllerForIdentifier:handles[i]], nil);
  }

  // Close all windows
  [engine.windowController closeAllWindows];

  // Verify all windows are closed and view controllers are disposed
  for (int i = 0; i < kWindowCount; ++i) {
    EXPECT_EQ([engine viewControllerForIdentifier:handles[i]], nil);
  }

@yiiim yiiim changed the title After a hot restart in multi-window mode, all windows should be closed. Fix the issue on macOS where, after a hot restart with multiple windows, unresponsive windows are left behind. Dec 25, 2025
@yiiim yiiim requested a review from knopp December 25, 2025 15:13
@hellohuanlin
Copy link
Contributor

@knopp from triage: do you plan to review this? thanks

Copy link
Member

@knopp knopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except the question for the test.

@yiiim yiiim force-pushed the multiple_window_macos_fix branch from 1926b90 to c388202 Compare January 19, 2026 10:12
@yiiim yiiim force-pushed the multiple_window_macos_fix branch from c388202 to be7a813 Compare January 19, 2026 15:38
@yiiim yiiim requested a review from knopp January 20, 2026 01:28
Copy link
Member

@knopp knopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks.

@yiiim yiiim added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 22, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Jan 22, 2026

autosubmit label was removed for flutter/flutter/180287, because This PR has not met approval requirements for merging. Changes were requested by {knopp}, please make the needed changes and resubmit this PR.
The PR author is a member of flutter-hackers and needs 2 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@knopp knopp added this pull request to the merge queue Jan 28, 2026
Merged via the queue into flutter:master with commit f1a74f4 Jan 28, 2026
180 of 181 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 29, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jan 29, 2026
Roll Flutter from dfd92b773219 to da72d5936d69 (39 revisions)

flutter/flutter@dfd92b7...da72d59

2026-01-29 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[ Tool / Engine ] Cleanup x86 references (#181152)" (flutter/flutter#181643)
2026-01-29 [email protected] Roll Skia from 174db42b7300 to 89df65f8324c (2 revisions) (flutter/flutter#181636)
2026-01-29 [email protected] [material/menu_anchor.dart] Add animations to MenuAnchor. (flutter/flutter#176494)
2026-01-28 [email protected] Roll Skia from 8e09f8a82251 to 174db42b7300 (6 revisions) (flutter/flutter#181627)
2026-01-28 [email protected] Send statusBarTouch events via dedicated messages (flutter/flutter#179643)
2026-01-28 [email protected] test: Improve DropdownMenuFormField tests (flutter/flutter#181369)
2026-01-28 [email protected] Account for vec3 padding in Metal (flutter/flutter#181563)
2026-01-28 [email protected] [ Tool / Engine ] Cleanup x86 references (flutter/flutter#181152)
2026-01-28 [email protected] Fix the issue on macOS where, after a hot restart with multiple windows, unresponsive windows are left behind. (flutter/flutter#180287)
2026-01-28 [email protected] Roll Skia from 675444e94bc9 to 8e09f8a82251 (7 revisions) (flutter/flutter#181606)
2026-01-28 [email protected] Roll Packages from e37af11 to 1cb2148 (5 revisions) (flutter/flutter#181608)
2026-01-28 [email protected] fix: swap app and engine version in vk::ApplicationInfo (flutter/flutter#181432)
2026-01-28 [email protected] Adds impeller backend to skia gold client (flutter/flutter#181503)
2026-01-28 [email protected] Remove chrome_and_driver dependency where it's not needed (flutter/flutter#178174)
2026-01-28 [email protected] chore: Windows_mokey basic_material_app_win__compile !bringup (flutter/flutter#180985)
2026-01-28 [email protected] Fix generating both `settings.gradle` and `settings.gradle.kts` for plugins (flutter/flutter#181592)
2026-01-28 [email protected] Roll Skia from 6614f89de521 to 675444e94bc9 (3 revisions) (flutter/flutter#181587)
2026-01-28 [email protected] Fix `todayBorder` todayBorder color is incorrectly overridden by `todayForegroundColor` in CalendarDatePicker (flutter/flutter#178792)
2026-01-28 [email protected] Roll Skia from 8f1695a4b328 to 6614f89de521 (2 revisions) (flutter/flutter#181583)
2026-01-28 [email protected] feat: add RoundedSuperellipseInputBorder (flutter/flutter#177220)
2026-01-28 [email protected] Roll Dart SDK from 38e351498549 to f10dcbfca98f (2 revisions) (flutter/flutter#181582)
2026-01-28 [email protected] Roll Skia from f424d58e37a3 to 8f1695a4b328 (6 revisions) (flutter/flutter#181577)
2026-01-28 [email protected] Remove unused code paths  in `PlatformViewsController.java` (flutter/flutter#181393)
2026-01-28 [email protected] feat: add onEnd to AnimatedCrossFade (flutter/flutter#181455)
2026-01-28 [email protected] Don't pass bounds to saveLayer call when painting ImageFilter (flutter/flutter#181353)
2026-01-28 [email protected] test: Clarify failure messages on gestures/debug_test.dart (flutter/flutter#181109)
2026-01-27 [email protected] Roll Fuchsia Linux SDK from akraNGn2lw4T1msgZ... to adhoq9ouVRh0xzkm3... (flutter/flutter#181571)
2026-01-27 [email protected] Roll Dart SDK from 4c7cb0a1d07d to 38e351498549 (4 revisions) (flutter/flutter#181570)
2026-01-27 [email protected] Make sure that an AnimatedPadding doesn't crash in 0x0 environment (flutter/flutter#181235)
2026-01-27 [email protected] Make sure that an ImageFiltered doesn't crash at 0x0 environment (flutter/flutter#181067)
2026-01-27 [email protected] Marks firebase_release_smoke_test to be unflaky (flutter/flutter#181308)
2026-01-27 [email protected] Fix remove material import box decoration test (flutter/flutter#181253)
2026-01-27 [email protected] Roll Skia from c2754838b077 to f424d58e37a3 (8 revisions) (flutter/flutter#181564)
2026-01-27 [email protected] Make sure that an AnimatedAlign doesn't crash in 0x0 environment (flutter/flutter#181361)
2026-01-27 [email protected] Make sure that an ImageIcon doesn't crash in 0x0 environment (flutter/flutter#181099)
2026-01-27 [email protected] Make sure that an AnimatedContainer doesn't crash in 0x0 environment (flutter/flutter#181198)
2026-01-27 [email protected] Make sure that an AnimatedRotation doesn't crash in 0x0 environment (flutter/flutter#181486)
2026-01-27 [email protected] Make sure that an AnimatedPositionedDirectional doesn't crash in 0x0 … (flutter/flutter#181451)
2026-01-27 [email protected] Merge changelog for 3.38.8. (flutter/flutter#181558)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

...
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…ws, unresponsive windows are left behind. (flutter#180287)

There is currently an issue with multiple windows on macOS: after a hot
restart, new windows are created, but the original windows are not
closed. You can reproduce this by running examples/multiple_windows and
then performing a hot restart.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop engine flutter/engine related. See also e: labels. platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants