Skip to content

Conversation

janis-bhm
Copy link
Contributor

Objective

Fixes #21131

The ProcessorGatedReader tries to look up assets by path in the processor's AssetInfos so it can wait for the processor to be finished processing, and doesn't find an asset for a relative path, and so it errors, even though the asset exists, and is being processed.

Solution

Since the gated reader tries to look up processed assets by their path, the path
should be normalized for this operation.

Testing

cd crates/bevy_asset; cargo test


because of lifetimes, I'm not sure it's possible to read the processed asset with the same normalized path here.
I would expect both the path and the normalized path to resolve to the same file on the file system, ofc because filesystems are the worst enemy of the programmer, this isn't guaranteed to be the case, but I think it's a reasonable expectation here. Notably, this doesn't fix potential issues with symlinks.

@janis-bhm janis-bhm added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 19, 2025
@andriyDev andriyDev self-requested a review September 19, 2025 23:19
Copy link
Contributor

@andriyDev andriyDev left a comment

Choose a reason for hiding this comment

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

I think this is the wrong move. I think we should be canonicalizing the asset path ASAP. These relative paths mean that loading "sprites/face.png" might be considered a different asset from "sprites/../sprites/face.png", and loaded separately.

@janis-bhm
Copy link
Contributor Author

Good point. I'm generally scared of making bigger changes than I have to, but personally I think it makes sense to basically normalize any path that potentially interacts with the path-to-id mapping

@janis-bhm janis-bhm changed the title Normalize paths in ProcessorGatedReader read and read_meta Normalize path component in AssetPath constructors and From impls Sep 20, 2025
@janis-bhm
Copy link
Contributor Author

These commits changed the scope of the PR significantly..

/// Normalizes the path by collapsing all occurrences of '.' and '..' dot-segments where possible
/// as per [RFC 1808](https://datatracker.ietf.org/doc/html/rfc1808)
/// Returns a borrowed path if no normalization was necessary, otherwise returns an owned normalized path.
pub(crate) fn maybe_normalize_path<'a, P: AsRef<Path> + Into<CowArc<'a, Path>> + 'a>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we fold this in with normalize_path above? Having two impls of the same thing is not great. Besides, the existing callsite could benefit from your improvements here. I think we can just return Cow<'a, Path>, and then convert that into a CowArc later (or in the case of the existing normalize_path, just don't set the result_path at all.

}
}

trait NormalizeCowPath {
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 like this magic. We only have a few callsites and this isn't pub anyway, so I'd prefer just making this a function that we call on our path instead of a trait.

Copy link
Contributor

@andriyDev andriyDev left a comment

Choose a reason for hiding this comment

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

Can we also add a test for this now? We can just load two file paths, one normalized and one denormalized, and check that their handles are the same.

@janis-bhm janis-bhm force-pushed the asset/processed-relative-paths branch from d1df8c6 to 7911517 Compare September 24, 2025 11:32
@janis-bhm
Copy link
Contributor Author

rebase

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 S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asset loading not behaving the same when using AssetMode::Processed
2 participants