Skip to content
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

Don't update app if we're already exiting #13203

Closed
wants to merge 2 commits into from

Conversation

Brezak
Copy link
Contributor

@Brezak Brezak commented May 3, 2024

Objective

As was notice on discord. Running an app currently output ERROR bevy_winit: Failed to send a app exit notification! This is a bug. Reason: sending on a full channel. This happens because after triggering a event loop exit we still receive queued events. This triggers the event loop exit code again causing the warning. If one of the events we receive is AboutToWait we also update the app which goes against the promise made in the AppExit documentation.

Solution

  • Add a exit_happened flag that gets set when we trigger a app exit.
  • After a app exit has been triggered. Only handle the LoopExiting event.
  • While handling the LoopExiting event send the AppExit that triggered the exit to the winit_runner.

Testing

  • Run the scene 3d example.
cargo run --example 3d_scene
  • Close the window.
  • You should only see one No windows are open, exiting message and no errors.

If somebody could test this code on wasm I'd really appreciate it. Every time I try to do it I get a GPU lacks support: TextureFormat::R16Float does not support TextureUsages::STORAGE_BINDING. error, so I can't test it myself.

@Brezak Brezak force-pushed the dont-update-after-app-exit branch from d2bf08e to 2bfe288 Compare May 3, 2024 12:49
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Windowing Platform-agnostic interface layer to run your app in S-Needs-Testing Testing must be done before this is safe to merge labels May 3, 2024
@alice-i-cecile alice-i-cecile added this to the 0.14 milestone May 3, 2024
@JMS55
Copy link
Contributor

JMS55 commented May 3, 2024

If somebody could test this code on wasm I'd really appreciate it. Every time I try to do it I get a GPU lacks support: TextureFormat::R16Float does not support TextureUsages::STORAGE_BINDING. error, so I can't test it myself.

It's a warning that ScreenSpaceAmbientOcclusionPlugin will not work on wasm. It won't affect anything unless you're using SSAO, which if off by default.

@Brezak
Copy link
Contributor Author

Brezak commented May 3, 2024

If somebody could test this code on wasm I'd really appreciate it. Every time I try to do it I get a GPU lacks support: TextureFormat::R16Float does not support TextureUsages::STORAGE_BINDING. error, so I can't test it myself.

It's a warning that ScreenSpaceAmbientOcclusionPlugin will not work on wasm. It won't affect anything unless you're using SSAO, which if off by default.

It dies after emitting that. I just assumed the warning was connected. I'll still need somebody else to tests it. Both to check if the error is only on my side and because I just can't test test the code if it dies.

@BD103 BD103 self-requested a review May 3, 2024 17:34
@kristoff3r
Copy link
Contributor

wasm is kinda broken on main until #13210 lands. When I rebase this on top of that PR it seems to work on wasm though.

Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

Looks good! I have a few small suggestions, but they're non-blocking. The one thing I was not able to test was closing a window to exit the app. For some reason it is freezing on my laptop. (It's on main too, though, not just you.)

Edit: It's freezing because of #13208, so don't worry about it. If someone else to test closing a window to exit an app, that would be great! :)

crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
@Brezak Brezak force-pushed the dont-update-after-app-exit branch from 2bfe288 to 851b21a Compare May 4, 2024 10:01
@alice-i-cecile alice-i-cecile removed the S-Needs-Testing Testing must be done before this is safe to merge label May 4, 2024
@JMS55 JMS55 mentioned this pull request May 4, 2024
Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

My PR here #13236 chose to just use event_loop.exiting() which I think is simpler. I agree with the outstanding question about whether it makes sense to process events after exit has been signaled or not. If it is indeed true that we guarantee nothing happens after exit has been called, it makes sense to swallow additional incoming events. However, I don't understand all the ceremony around exit_happened and processing the LoopExiting event. Personally, i'd just wrap the entire handler in if !event_loop.exiting().

@@ -772,13 +788,28 @@ fn handle_winit_event(
Event::UserEvent(RequestRedraw) => {
runner_state.redraw_requested = true;
}
Event::LoopExiting => {
let exit = exit_happened.clone().unwrap_or_else(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is unreachable. We only receive this event if we call event_loop.exit(), which is guaranteed to have set *exit_happened = Some(app_exit).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The event drop code specifically let's through the LoopExiting event.

if exit_happened.is_some() && event != Event::LoopExiting {
debug!("App is exiting. Dropping event: {event:?}");
return;
}

I didn't put much thought into my solution as I know this code will get replaced soonTM. I'd modify your solution to drop events after we start exiting the event loop and merge it instead of this one. That's not my call to make though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just saying we'll only receive LoopExiting if we've already called event_loop.exit() which in the control flow here guarantees exit_happened is Some. Agree that this code will likely change a lot post non-send changes.

@alice-i-cecile
Copy link
Member

Closed in favor of #13236.

@Brezak Brezak deleted the dont-update-after-app-exit branch May 12, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants