asset: make HandleUntyped::id private (#7076)
# Objective It is currently possible to break reference counting for assets by creating a strong `HandleUntyped` and then modifying the `id` field before dropping the handle. This should not be allowed. ## Solution Change the `id` field visibility to private and add a getter instead. The same change was previously done for `Handle<T>` in #6176, but `HandleUntyped` was forgotten. --- ## Migration Guide - Instead of directly accessing the ID of a `HandleUntyped` as `handle.id`, use the new getter `handle.id()`.
This commit is contained in:
parent
4fff0ce837
commit
85743ce49e
@ -322,8 +322,7 @@ impl<T: Asset> Clone for Handle<T> {
|
|||||||
/// To convert back to a typed handle, use the [typed](HandleUntyped::typed) method.
|
/// To convert back to a typed handle, use the [typed](HandleUntyped::typed) method.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HandleUntyped {
|
pub struct HandleUntyped {
|
||||||
/// An unique identifier to an Asset.
|
id: HandleId,
|
||||||
pub id: HandleId,
|
|
||||||
handle_type: HandleType,
|
handle_type: HandleType,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +351,12 @@ impl HandleUntyped {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The ID of the asset.
|
||||||
|
#[inline]
|
||||||
|
pub fn id(&self) -> HandleId {
|
||||||
|
self.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a weak copy of this handle.
|
/// Creates a weak copy of this handle.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn clone_weak(&self) -> Self {
|
pub fn clone_weak(&self) -> Self {
|
||||||
|
@ -34,8 +34,8 @@ fn check_textures(
|
|||||||
rpg_sprite_handles: ResMut<RpgSpriteHandles>,
|
rpg_sprite_handles: ResMut<RpgSpriteHandles>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
if let LoadState::Loaded =
|
if let LoadState::Loaded = asset_server
|
||||||
asset_server.get_group_load_state(rpg_sprite_handles.handles.iter().map(|handle| handle.id))
|
.get_group_load_state(rpg_sprite_handles.handles.iter().map(|handle| handle.id()))
|
||||||
{
|
{
|
||||||
state.set(AppState::Finished).unwrap();
|
state.set(AppState::Finished).unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user