bevy/crates/bevy_asset/src
Carter Anderson 0a588dbfd9
Allow removing and reloading assets with live handles (#10785)
# Objective

Fixes #10444 

Currently manually removing an asset prevents it from being reloaded
while there are still active handles. Doing so will result in a panic,
because the storage entry has been marked as "empty / None" but the ID
is still assumed to be active by the asset server.

Patterns like `images.remove() -> asset_server.reload()` and
`images.remove() -> images.insert()` would fail if the handle was still
alive.

## Solution

Most of the groundwork for this was already laid in Bevy Asset V2. This
is largely just a matter of splitting out `remove` into two separate
operations:

* `remove_dropped`: remove the stored asset, invalidate the internal
Assets entry (preventing future insertions with the old id), and recycle
the id
* `remove_still_alive`: remove the stored asset, but leave the entry
otherwise untouched (and dont recycle the id).

`remove_still_alive` and `insert` can be called any number of times (in
any order) for an id until `remove_dropped` has been called, which will
invalidate the id.

From a user-facing perspective, there are no API changes and this is non
breaking. The public `Assets::remove` will internally call
`remove_still_alive`. `remove_dropped` can only be called by the
internal "handle management" system.

---

## Changelog

- Fix a bug preventing `Assets::remove` from blocking future inserts for
a specific `AssetIndex`.
2023-11-29 23:32:13 +00:00
..
io Print precise and correct watch warnings (and only when necessary) (#10787) 2023-11-29 00:35:13 +00:00
processor Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
server Fix GLTF scene dependencies and make full scene renders predictable (#10745) 2023-11-27 22:42:28 +00:00
assets.rs Allow removing and reloading assets with live handles (#10785) 2023-11-29 23:32:13 +00:00
event.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
folder.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
handle.rs remove double-hasing of typeid for handle (#10699) 2023-11-23 01:04:37 +00:00
id.rs Fix Asset Loading Bug (#10698) 2023-11-22 13:39:44 +00:00
lib.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
loader.rs Fix GLTF scene dependencies and make full scene renders predictable (#10745) 2023-11-27 22:42:28 +00:00
meta.rs assets: use blake3 instead of md5 (#10208) 2023-10-23 04:15:04 +00:00
path.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
reflect.rs Add clippy::manual_let_else at warn level to lints (#10684) 2023-11-28 04:15:27 +00:00
saver.rs Make AssetLoader/Saver Error type bounds compatible with anyhow::Error (#10493) 2023-11-14 01:25:06 +00:00