bevy/crates/bevy_window/src
Friz64 9973f0c8a3
Introduce a WindowWrapper to extend the lifetime of the window when using pipelined rendering (#12978)
# Objective

A `RawWindowHandle` is only valid as long as the window it was retrieved
from is alive. Extend the lifetime of the window, so that the
`RawWindowHandle` doesn't outlive it, and bevy doesn't crash when
closing a window a pipelined renderer is drawing to.

- Fix #11236
- Fix #11150
- Fix #11734
- Alternative to / Closes #12524

## Solution

Introduce a `WindowWrapper` that takes ownership of the window. Require
it to be used when constructing a `RawHandleWrapper`. This forces
windowing backends to store their window in this wrapper.

The `WindowWrapper` is implemented by storing the window in an `Arc<dyn
Any + Send + Sync>`.

We use dynamic dispatch here because we later want the
`RawHandleWrapper` to be able dynamically hold a reference to any
windowing backend's window.

But alas, the `WindowWrapper` itself is still practically invisible to
windowing backends, because it implements `Deref` to the underlying
window, by storing its type in a `PhantomData`.

---

## Changelog

### Added

- Added `WindowWrapper`, which windowing backends are now required to
use to store their underlying window.

### Fixed

- Fixed a safety problem which caused crashes when closing bevy windows
when using pipelined rendering.

## Migration Guide

- Windowing backends now need to store their window in the new
`WindowWrapper`.
2024-04-30 14:13:07 +00:00
..
cursor.rs Update cursor.rs (#11617) 2024-01-30 16:34:17 +00:00
event.rs Deprecate ReceivedCharacter (#12868) 2024-04-30 00:49:41 +00:00
lib.rs Deprecate ReceivedCharacter (#12868) 2024-04-30 00:49:41 +00:00
raw_handle.rs Introduce a WindowWrapper to extend the lifetime of the window when using pipelined rendering (#12978) 2024-04-30 14:13:07 +00:00
system.rs Make AppExit more specific about exit reason. (#13022) 2024-04-22 16:48:18 +00:00
window.rs Expose desired_maximum_frame_latency through window creation (#12954) 2024-04-19 23:09:30 +00:00