bevy/crates
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
..
bevy_a11y Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_animation Expose mutable Animation Clips (#13067) 2024-04-23 14:58:08 +00:00
bevy_app Update App:is_plugin_added to work inside Plugin::finish and Plugin::clean (#12761) 2024-04-28 21:32:16 +00:00
bevy_asset Fix Clippy lints on WASM (#13030) 2024-04-20 09:15:42 +00:00
bevy_audio Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
bevy_color Fix crates not building individually (#12948) 2024-04-14 00:06:03 +00:00
bevy_compile_test_utils Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_core Fix beta lints (#12980) 2024-04-16 02:46:46 +00:00
bevy_core_pipeline Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_derive Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_dev_tools Make AppExit more specific about exit reason. (#13022) 2024-04-22 16:48:18 +00:00
bevy_diagnostic Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
bevy_dylib Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_dynamic_plugin Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_ecs Make from_reflect_or_world also try ReflectDefault and improve some comments and panic messages (#12499) 2024-04-30 00:48:46 +00:00
bevy_ecs_compile_fail_tests Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_encase_derive Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_gilrs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_gizmos Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_gltf Fix crates not building individually (#12948) 2024-04-14 00:06:03 +00:00
bevy_hierarchy fix bevy_hierarchy crate optional feature bevy_app (#12943) 2024-04-13 04:46:00 +00:00
bevy_input Added ButtonInput docs usage example (#13046) 2024-04-22 17:48:46 +00:00
bevy_internal Switch monolithic lib to module re-exports (#13059) 2024-04-22 01:32:51 +00:00
bevy_log Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
bevy_macro_utils Clean up some low level dependencies (#12858) 2024-04-08 19:45:42 +00:00
bevy_macros_compile_fail_tests Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_math Use Vec3A for 3D bounding volumes and raycasts (#13087) 2024-04-25 18:56:58 +00:00
bevy_mikktspace Enable clippy::ref_as_ptr (#12918) 2024-04-10 20:16:48 +00:00
bevy_pbr Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_ptr chore: fix some comments (#13083) 2024-04-25 19:09:16 +00:00
bevy_reflect iter_with_data (#13102) 2024-04-26 02:09:34 +00:00
bevy_reflect_compile_fail_tests Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_render Don't ignore unbatchable sorted items. (#13144) 2024-04-30 07:02:59 +00:00
bevy_scene Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
bevy_sprite Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_tasks Remove async-task as a dependency (#13071) 2024-04-23 14:57:55 +00:00
bevy_text Fix beta lints (#12980) 2024-04-16 02:46:46 +00:00
bevy_time Fix uses of "it's" vs "its". (#13033) 2024-04-19 18:17:31 +00:00
bevy_transform Fix Clippy lints on WASM (#13030) 2024-04-20 09:15:42 +00:00
bevy_ui Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_utils Improve par_iter and Parallel (#12904) 2024-04-23 12:05:34 +00:00
bevy_window Introduce a WindowWrapper to extend the lifetime of the window when using pipelined rendering (#12978) 2024-04-30 14:13:07 +00:00
bevy_winit Introduce a WindowWrapper to extend the lifetime of the window when using pipelined rendering (#12978) 2024-04-30 14:13:07 +00:00