Skip to content

Commit bd4cbc8

Browse files
committed
Make sure swapchain texture views are dropped.
1 parent 64c7bec commit bd4cbc8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

crates/bevy_render/src/view/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
render_asset::RenderAssets,
1717
render_phase::ViewRangefinder3d,
1818
render_resource::{DynamicUniformBuffer, ShaderType, Texture, TextureView},
19-
renderer::{RenderDevice, RenderQueue},
19+
renderer::{RenderAdapterInfo, RenderDevice, RenderQueue},
2020
sync_world::MainEntity,
2121
texture::{
2222
CachedTexture, ColorAttachment, DepthAttachment, GpuImage, ManualTextureViews,
@@ -117,6 +117,9 @@ impl Plugin for ViewPlugin {
117117
clear_view_attachments
118118
.in_set(RenderSystems::ManageViews)
119119
.before(create_surfaces),
120+
cleanup_view_targets_for_resize
121+
.in_set(RenderSystems::ManageViews)
122+
.before(create_surfaces),
120123
prepare_view_attachments
121124
.in_set(RenderSystems::ManageViews)
122125
.before(prepare_view_targets)
@@ -1040,6 +1043,22 @@ pub fn clear_view_attachments(mut view_target_attachments: ResMut<ViewTargetAtta
10401043
view_target_attachments.clear();
10411044
}
10421045

1046+
pub fn cleanup_view_targets_for_resize(
1047+
mut commands: Commands,
1048+
windows: Res<ExtractedWindows>,
1049+
cameras: Query<(Entity, &ExtractedCamera), With<ViewTarget>>,
1050+
) {
1051+
for (entity, camera) in &cameras {
1052+
if let Some(NormalizedRenderTarget::Window(window_ref)) = &camera.target {
1053+
if let Some(window) = windows.get(&window_ref.entity()) {
1054+
if window.size_changed || window.present_mode_changed {
1055+
commands.entity(entity).remove::<ViewTarget>();
1056+
}
1057+
}
1058+
}
1059+
}
1060+
}
1061+
10431062
pub fn prepare_view_targets(
10441063
mut commands: Commands,
10451064
clear_color_global: Res<ClearColor>,

crates/bevy_render/src/view/window/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ pub fn create_surfaces(
413413
// normally this is dropped on present but we double check here to be safe as failure to
414414
// drop it will cause validation errors in wgpu
415415
drop(window.swap_chain_texture.take());
416+
drop(window.swap_chain_texture_view.take());
416417

417418
data.configuration.width = window.physical_width;
418419
data.configuration.height = window.physical_height;

0 commit comments

Comments
 (0)