-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Handle<T>::as_weak() takes a type U which is potentially bad #3522
Comments
bevy/crates/bevy_text/src/glyph_brush.rs Line 99 in ffecb05
In this line a Handle<Font> is changed to a Handle<FontAtlasSet> . This is used for easy correspondence between fonts assets and font atlas assets as they share the same handle
|
Indeed. But since this is the only use case for it, I think what this method needs is a new name to make its intent more clear: |
Imo we should avoid I do think its worth trying to sort out a way to make font atlas set UX reasonable without requiring handle casting. |
I have renamed it to
Yeah. Since this is currently the only use case for that method, I think there's two ways we could go about this:
And then we should probably rename this issue accordingly. |
# Objective Following discussion on #3536 and #3522, `Handle::as_weak()` takes a type `U`, reinterpreting the handle as of another asset type while keeping the same ID. This is mainly used today in font atlas code. This PR does two things: - Rename the method to `cast_weak()` to make its intent more clear - Actually change the type uuid in the handle if it's not an asset path variant. ## Migration Guide - Rename `Handle::as_weak` uses to `Handle::cast_weak` The method now properly sets the associated type uuid if the handle is a direct reference (e.g. not a reference to an `AssetPath`), so adjust you code accordingly if you relied on the previous behavior.
# Objective Following discussion on bevyengine#3536 and bevyengine#3522, `Handle::as_weak()` takes a type `U`, reinterpreting the handle as of another asset type while keeping the same ID. This is mainly used today in font atlas code. This PR does two things: - Rename the method to `cast_weak()` to make its intent more clear - Actually change the type uuid in the handle if it's not an asset path variant. ## Migration Guide - Rename `Handle::as_weak` uses to `Handle::cast_weak` The method now properly sets the associated type uuid if the handle is a direct reference (e.g. not a reference to an `AssetPath`), so adjust you code accordingly if you relied on the previous behavior.
I can't find |
On discord https://discord.com/channels/691052431525675048/749332104487108618/927078698035855420 while working on documenting bevy_assets @manokara noticed Handle::as_weak() takes a type U and wondered if "the handle would be invalid if U is different from T?"
@mockersf noted that "there's one place where that is used to convert a Handle to a Handle," and upon further investigation concluded that "the FontAtlasSet asset storage is handled manually, to have its handles in sync with fonts."
@mockersf said that this is "potentially bad and would require more thinking to improve," so I have created this issue to see what others think of the degree to which this is potentially bad and be a starting point for discussions of how to improve this.
The text was updated successfully, but these errors were encountered: