Skip to content

Commit

Permalink
iter_mut on Assets: send modified event only when asset is iterated…
Browse files Browse the repository at this point in the history
… over (#3565)

# Objective

- `Assets<T>::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>
  • Loading branch information
mockersf and mockersf committed Mar 5, 2022
1 parent 6c95b58 commit baae97d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ impl<T: Asset> Assets<T> {

/// Get a mutable iterator over all assets in the collection.
pub fn iter_mut(&mut self) -> impl Iterator<Item = (HandleId, &mut T)> {
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.
Expand Down

0 comments on commit baae97d

Please sign in to comment.