-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix embedded asset path manipulation #10383
Conversation
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
1 similar comment
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
Path manipulation is far less error prone when using the std::path::Path API. This lets us remove all instances of "/" which is not a portable path separator.
96440ff
to
cc90faf
Compare
I tested it with wasm-server-runner, and it should work.
f4f1684
to
41e6bfb
Compare
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
The generated |
1 similar comment
The generated |
After submitting this issue for
I think this means you might try to do this in embedded_asset!(app, "my_asset.png");
...
let asset = server.load("embedded://my_crate/my_asset.png"); And I think this is a case where the old behavior could have worked properly (not on Windows).
It might be challenging to test this 😓 . |
I've addressed the external crate issue. I was able to test this by creating a git repo with a crate that embeds an asset, loads it, and spawns it. Then I made another local crate that depends on this git repo and adds the plugin. As anticipated, it would fail to load the asset without the f8e8e0d fix. The fix... fixes it. This was a relatively involved integration test. If we want to keep this around, we could transfer ownership of the test repo to the bevyengine org and make another example. |
WASM CI failure looks unrelated to my changes. |
09f2b91
to
bc097db
Compare
This includes if cargo is building a crate that depends on some crates.io or git repo crate that contains embedded assets.
bc097db
to
f8e8e0d
Compare
@viridia could I get your review here? |
So I guess I'm being brought into this because of the prior discussion about wanting to remove the use of As far as the rest, I'm not familiar enough with the details of embedded assets to give a useful opinion. I guess I would ask whether this logic is something that belongs in |
I'm surprised by this. Isn't the whole point of |
@bonsairobo The problem is that |
@viridia OK sounds like RE: This PR. Anything we get from |
Sorry for not responding sooner, dealing with some health issues. The latest discussion is #10511. |
@shanecelis @doonv could I get a review on this from one or both of you? I'd like to unblock the linked PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really a fan of the "double path" thing where you have to first have the path inside the embedded_asset!
macro, and then the path every time you want to access the asset.
I'd rather have something more similar to what we had earlier with load_internal_asset!
. Where you stored the handle in a static
variable.
I think that's out of scope for this PR, which is not changing the public API. |
@doonv Re: Handle vs double path I've converted some code from using
Now kayak_ui's module that has the handles to its shaders as
I thought that was a win for But I agree the many paths—a file system source path, an asset-path, an embedded://crate-name/asset-path—is confusing, especially at first. One thing I would really like is if |
I added some more tests in a PR bonsairobo#1 to this PR to exercise its behavior on error conditions. I never provoked an unwrap() None error, so I'm happy with that. And I prefer this to my own PR #11340 which merely reports errors. This PR interrogates the paths as |
test: Add tests, include failure conditions.
Is this going into the next release? |
Unlikely: it needs two community approvals before it can merged by maintainers. If this interests you, please feel free to leave a code review! |
I wasn't aware of this process. Is there anything blocking approval by @doonv and @shanecelis? |
No, nothing blocking. I’ll be happy to approve. I added some tests and exercised it. It’d be nice for this to make it in. I don’t see the approve button here on mobile. Will search for it on my computer shortly. |
Go to the "Files changed" tab, then "Review changes", then "Approve" :) |
Done. Thank you, @alice-i-cecile. Great talk on reflection by the way. |
# Objective Fixes bevyengine#10377 ## Solution Use `Path::strip_prefix` instead of `str::split`. Avoid any explicit "/" characters in path manipulation. --- ## Changelog - Added: example of embedded asset loading - Added: support embedded assets in external crates - Fixed: resolution of embedded assets - Fixed: unexpected runtime panic during asset path resolution ## Migration Guide No API changes. --------- Co-authored-by: Shane Celis <shane.celis@gmail.com>
Objective
Fixes #10377
Solution
Use
Path::strip_prefix
instead ofstr::split
. Avoid any explicit "/" characters in path manipulation.Changelog
Migration Guide
No API changes.