Bevy, on Web and WebGL, doesn't exit winit's Event Loop cleanly after a GPU crash. It panics twice with already borrowed: BorrowMutError
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
Latest released Bevy atow, which is 0.13.2
This can be reproduced at the Bevy examples posted on the web
## Relevant system information
I am able to reproduce this both with Google Chrome and Firefox, both in a M1 Macbook and a Windows 11 laptop
## What you did (repro steps)
- Open this link: https://bevyengine.org/examples/Application/logs/
- Open the JS console on the devtools (you can press F12)
- Disable info logs to not clutter your console with the messages that the example logs every frame
- Click on the example canvas to gain focus
- Press P to panic, as usual
- You will see an error like this. This is normal and expected, it's a deliberated panic, part of the example:
Now, let's reproduce the actual issue
- Refresh the page, click to gain focus. Now, instead of pressing P:
- Write this into the JS console to simulate a GPU crash `document.querySelector("#bevy").getContext('webgl2').getExtension("WEBGL_lose_context").loseContext()`
- The example will crash, **this is expected too, it is a known issue**. For reference, see:
- https://github.com/bevyengine/bevy/issues/12681
- https://github.com/bevyengine/bevy/issues/10456
- The crash will of course be related to `wgpu`, `glow`, and graphics code, like this:
**Unexpected behaviour comes here.**
- Instead of showing only 1 panic: the panic that occurred
- **FAIL:** It shows an additional `BorrowMutError` panic. See:
`wasm_example.js:502 panicked at [...]/winit-0.29.15/src/platform_impl/web/event_loop/runner.rs:625:30:
already borrowed: BorrowMutError`
## What went wrong
_- what were you expecting?_
I was expecting to see a single crash. This is needed in production environments to uniquely report crashes for analytics and error tracking, and avoiding redundancies.
_- what actually happened?_
Winit seems to be exiting the event loop in a wrong way, causing yet another panic, which is then handled by the `console_error_panic_hook` and logged as well
## Additional information
- As an alternative to simulating a GPU crash by calling the WebGL2 extension, in Google Chrome, we can also write `chrome://gpucrash/` in the address bar and press enter to simulate it at a browser level. Same happens
- This can't be reproduced on the WebGPU example because WebGPU doesn't crash upon a GPU context loss
- I'm opening the issue here instead of on Winit's repo because, since Winit web examples don't use WebGL nor graphics, I couldn't reproduce this on them.
- Update: I've tried setting up a minimal Winit loop example that crases when losing the WebGL context, and I haven't been able to reproduce this, which suggests it may be caused by Bevy, or by how Bevy sets up the Winit's loop?
Contributor guide
Assessment
This issue has not been assessed yet.