Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/bevy_render/src/view/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,29 @@ fn extract_windows(
}
}

// Remove the components instead of despawn the synced render entity here:
// `RawHandleWrapper` removal is not necessarily
// terminal. On Android the native window is destroyed (and its handle removed) when the app
// suspends, but the window entity survives and is given a new handle on resume. Despawning
// would leave the `SubEntity` on the main world entity pointing at a dead entity, and the
// next round of extraction would panic when reusing it.
//
// The render entity is only ever despawned by the entity sync system once the main world
// window entity is actually destroyed. Here we only tear down the surface and drop the
// extracted window data; extraction and `create_surfaces` will recreate them whenever the
// window has a (new) `RawHandleWrapper` again.
for closing_window in closing.read() {
if let Ok(render_entity) = mapper.get(closing_window.window) {
commands.entity(render_entity.entity()).despawn();
commands
.entity(render_entity.entity())
.remove::<(ExtractedWindow, RawHandleWrapper, SurfaceData)>();
}
}
for removed_window in removed.read() {
if let Ok(render_entity) = mapper.get(removed_window) {
commands.entity(render_entity.entity()).despawn();
commands
.entity(render_entity.entity())
.remove::<(ExtractedWindow, RawHandleWrapper, SurfaceData)>();
}
}
for removed_window in removed_primary.read() {
Expand Down