From baae97d002e6c84be9a656b8ab7405d234b15fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 5 Mar 2022 21:25:30 +0000 Subject: [PATCH] `iter_mut` on Assets: send modified event only when asset is iterated over (#3565) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - `Assets::iter_mut` sends `Modified` event for all assets first, then returns the iterator - This means that events could be sent for assets that would not have been mutated if iteration was stopped before ## Solution - Send `Modified` event when assets are iterated over. Co-authored-by: François <8672791+mockersf@users.noreply.github.com> --- crates/bevy_asset/src/assets.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 88a12226d4eff..a90afe5f20803 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -186,12 +186,12 @@ impl Assets { /// Get a mutable iterator over all assets in the collection. pub fn iter_mut(&mut self) -> impl Iterator { - for id in self.assets.keys() { + self.assets.iter_mut().map(|(k, v)| { self.events.send(AssetEvent::Modified { - handle: Handle::weak(*id), + handle: Handle::weak(*k), }); - } - self.assets.iter_mut().map(|(k, v)| (*k, v)) + (*k, v) + }) } /// Get an iterator over all [`HandleId`]'s in the collection.