-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Ensure clean exit #13236
Ensure clean exit #13236
Conversation
Fixes two issues related to bevyengine#13208. First, we ensure render resources for a window are always dropped first to ensure that the `winit::Window` always drops on the main thread when it is removed from `WinitWindows`. Previously, changes in bevyengine#12978 caused the window to drop in the render world, causing issues. We accomplish this by delaying despawning the window by a frame by inserting a marker component `ClosingWindow` that indicates the window has been requested to close and is in the process of closing. The render world now responds to the equivalent `WindowClosing` event rather than `WindowCloseed` which now fires after the render resources are guarunteed to be cleaned up. Secondly, fixing the above caused (revealed?) that additional events were being delivered to the the event loop handler after exit had already been requested: in my testing `RedrawRequested` and `LoopExiting`. This caused errors to be reported try to send an exit event on the close channel. There are two options here: - Guard the handler so no additional events are delivered once the app is exiting. I considered this but worried it might be confusing or bug prone if in the future someone wants to handle `LoopExiting` or some other event to clean-up while exiting. - Only send an exit signal if we are not already exiting. It doesn't appear to cause any problems to handle the extra events so this seems safer. Fixing this also appears to have fixed bevyengine#13231.
Is the latter issue with events firing after window close related to #13203? |
Yup, this looks like it's trying to fix the same issue. Happy to remove in favor of that PR. |
This works on my MacBook, but it will probably need testing on other platforms just in case. |
works for me, but there may be an issue with ordering in the logs:
I don't think this is sensitive for wasm or mobile, but testing on windows and linux would be good |
I think this is the same on main:
I'll test on windows later. |
Works fine on both Wayland and XWayland for me. |
Looks like we have some warnings to clean up:
I think we need to prevent any events being delivered post exit. Right now the PR just skips sending a second exit signal. |
This should be good now on windows. I changed the behavior to never deliver new events once we start exiting. #13203 does something similar, but I really think the simple approach is honestly fine. Happy to go either way. |
I think this PR should be merged instead of #13203. The only thing this PR is (debatably) missing is logging the winit events we have skipped. |
This fixes #10260. |
Objective
Fixes two issues related to #13208.
First, we ensure render resources for a window are always dropped first to ensure that the
winit::Window
always drops on the main thread when it is removed fromWinitWindows
. Previously, changes in #12978 caused the window to drop in the render world, causing issues.We accomplish this by delaying despawning the window by a frame by inserting a marker component
ClosingWindow
that indicates the window has been requested to close and is in the process of closing. The render world now responds to the equivalentWindowClosing
event rather thanWindowCloseed
which now fires after the render resources are guarunteed to be cleaned up.Secondly, fixing the above caused (revealed?) that additional events were being delivered to the the event loop handler after exit had already been requested: in my testing
RedrawRequested
andLoopExiting
. This caused errors to be reported try to send an exit event on the close channel. There are two options here:considered this but worried it might be confusing or bug prone if in the future someone wants to handleWe are now taking this approach.LoopExiting
or some other event to clean-up while exiting.It doesn't appear to cause any problems to handle the extra events so this seems safer.Fixing this also appears to have fixed #13231.
Fixes #10260.
Testing
Tested on mac only.
Changelog
Added
WindowClosing
event has been added that indicates the window will be despawned on the next frame.Changed
Migration Guide