Skip to content

Conversation

@andriyDev
Copy link
Contributor

@andriyDev andriyDev commented Dec 24, 2025

Objective

Solution

  • When allocating a new handle (whether for an existing asset or a new asset), send a "new" message to the same channel as "drop" events.
    • This essentially means we're "leaning in" to the fact that we can have multiple live handles to the same asset.
  • Assets::track_assets now increments when a "new" message is received, and decrements when a "drop" message is received. The asset entry is dropped if the counter is at 0 after processing all messages.
  • Remove the asset_server_managed flag, since we can just lookup the index to see if it's present.
  • Remove the handle_drops_to_skip counter since now we count all new handles, not just those in get_strong_handle.

Testing

  • Unbroke our reproduction test.
  • Added a new test to verify that "reacquiring" an asset doesn't drop the asset.

@andriyDev andriyDev requested a review from janis-bhm December 24, 2025 19:43
@andriyDev andriyDev added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 24, 2025
Copy link
Contributor

@kristoff3r kristoff3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the logic in track_assets felt a bit complicated but I couldn't find a way to simplify it.

/// Returns true if the asset's entry was removed. This is not the same as removing the asset
/// itself - an asset which has not been inserted may still have its entry removed.
pub(crate) fn try_remove_dropped(&mut self, index: AssetIndex) -> bool {
use bevy_platform::collections::hash_map::Entry;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this import needs to be inside this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file defines a type Entry, so the hashmap Entry collides with it. Scoping it here sidesteps that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dropping a handle from Assets::get_strong_handle has different behaviour to one from AssetServer::load.

2 participants