Asset can only be retrieved once #14819
-
Howdy y'all, I've been working on a project using apriltag-rust and nokhwa to find AprilTags in webcam frames and track shapes to them, but I'm currently running into a troubling issue. The issue is thus:
I'm using #[derive(Resource, Default)]
pub struct DebugImage(Handle<Image>); The resource is added with pub fn setup_image(
/*...*/
images: ResMut<Assets<Image>>,
debug_img: ResMut<DebugImage>,
/*...*/
) {
// <snip>
let mut img = Image::new_fill(
bevy::render::render_resource::Extent3d {
width: WIDTH,
height: HEIGHT,
depth_or_array_layers: 1,
},
TextureDimension::D2,
&[255, 255, 255, 255],
bevy::render::render_resource::TextureFormat::Rgba8Unorm,
RenderAssetUsages::RENDER_WORLD,
);
img.texture_descriptor.usage = TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING;
debug_img.0 = images.add(img);
// </snip>
} Then, later on, I try to retrieve the asset, which only seems to work once (based on debug printing). pub fn update_image(
/* ... */
mut images: ResMut<Assets<Image>>,
debug_image: Res<DebugImage>,
/* ... */
) {
let image = images
.get_mut(&debug_image.0.clone())
.unwrap_or_else(|| panic!("Unable to locate resource"));
} Here's a gist of the file the code resides in, though I modified some of the variable names for readability in the code examples here. Let me know if there's anything else I can provide, I'm really desperate to fix this issue, I truly have no idea what is causing it (this is my first bevy project :P). Thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Quick update: I've confirmed the handle stored in the resource is still always a strong handle, whether the |
Beta Was this translation helpful? Give feedback.
-
Update part 2: The asset with the handle does not have a load state (i.e. |
Beta Was this translation helpful? Give feedback.
-
Hi @mixolydianmel since your asset has |
Beta Was this translation helpful? Give feedback.
Hi @mixolydianmel since your asset has
RenderAssetUsages::RENDER_WORLD
, during Extract https://bevy-cheatbook.github.io/gpu/stages.html it will be removed from the main world after its extracted into the render world. I ran into this same issue last week and it caused me a lot of confusion. I solved it by setting the usage toRenderAssetUsages::RENDER_WORLD | RenderAssetUsages::MAIN_WORLD
. I'm not a bevy expert though so there may be details I'm missing.