From 2ec164d279d1ec5fb289df27c523299cb5fc004b Mon Sep 17 00:00:00 2001 From: akimakinai <105044389+akimakinai@users.noreply.github.com> Date: Tue, 1 Oct 2024 01:58:04 +0900 Subject: [PATCH] Clear view attachments before resizing window surfaces (#15087) # Objective - Fixes #15077 ## Solution - Clears `ViewTargetAttachments` resource every frame before `create_surfaces` system instead, which was previously done after `extract_windows`. ## Testing - Confirmed that examples no longer panic on window resizing with DX12 backend. - `screenshot` example keeps working after this change. --- crates/bevy_render/src/view/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index c8292d4f90..2a6d966705 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -118,6 +118,10 @@ impl Plugin for ViewPlugin { render_app.add_systems( Render, ( + // `TextureView`s need to be dropped before reconfiguring window surfaces. + clear_view_attachments + .in_set(RenderSet::ManageViews) + .before(create_surfaces), prepare_view_attachments .in_set(RenderSet::ManageViews) .before(prepare_view_targets) @@ -814,7 +818,6 @@ pub fn prepare_view_attachments( cameras: Query<&ExtractedCamera>, mut view_target_attachments: ResMut, ) { - view_target_attachments.clear(); for camera in cameras.iter() { let Some(target) = &camera.target else { continue; @@ -839,6 +842,11 @@ pub fn prepare_view_attachments( } } +/// Clears the view target [`OutputColorAttachment`]s. +pub fn clear_view_attachments(mut view_target_attachments: ResMut) { + view_target_attachments.clear(); +} + pub fn prepare_view_targets( mut commands: Commands, clear_color_global: Res,