diff --git a/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs b/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs index 0713e8599df36..61f463eb2d633 100644 --- a/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs @@ -6,6 +6,7 @@ use crate::{ use bevy_app::prelude::{EventReader, Events}; use bevy_asset::{AssetEvent, Assets}; use bevy_ecs::{Resources, World}; +use bevy_utils::{AHashExt, HashSet}; #[derive(Default)] pub struct TextureCopyNode { @@ -23,10 +24,15 @@ impl Node for TextureCopyNode { ) { let texture_events = resources.get::>>().unwrap(); let textures = resources.get::>().unwrap(); + let mut copied_textures = HashSet::new(); for event in self.texture_event_reader.iter(&texture_events) { match event { AssetEvent::Created { handle } | AssetEvent::Modified { handle } => { if let Some(texture) = textures.get(handle) { + if copied_textures.contains(&handle.id) { + continue; + } + let texture_descriptor: TextureDescriptor = texture.into(); let width = texture.size.x() as usize; let aligned_width = render_context @@ -67,6 +73,8 @@ impl Node for TextureCopyNode { texture_descriptor.size, ); render_context.resources().remove_buffer(texture_buffer); + + copied_textures.insert(&handle.id); } } AssetEvent::Removed { .. } => {}