{"record":{"id":"b452698ad46be0e3","repo":"bevyengine/bevy","slug":"image-has-no-texture-data","errorCode":null,"errorMessage":"Image has no texture data","messagePattern":"Image has no texture data","errorType":"exception","errorClass":"IntoDynamicImageError","httpStatus":null,"severity":"error","filePath":"crates/bevy_image/src/image_texture_conversion.rs","lineNumber":208,"sourceCode":"            self.texture_descriptor.format,\n        ))\n    }\n}\n\n/// Errors that occur while converting an [`Image`] into a [`DynamicImage`]\n#[non_exhaustive]\n#[derive(Error, Debug)]\npub enum IntoDynamicImageError {\n    /// Conversion into dynamic image not supported for source format.\n    #[error(\"Conversion into dynamic image not supported for {0:?}.\")]\n    UnsupportedFormat(TextureFormat),\n\n    /// Encountered an unknown error during conversion.\n    #[error(\"Failed to convert into {0:?}.\")]\n    UnknownConversionError(TextureFormat),\n\n    /// Tried to convert an image that has no texture data\n    #[error(\"Image has no texture data\")]\n    UninitializedImage,\n}\n\n#[cfg(test)]\nmod test {\n    use image::{GenericImage, Rgba};\n\n    use super::*;\n\n    #[test]\n    fn two_way_conversion() {\n        // Check to see if color is preserved through an rgba8 conversion and back.\n        let mut initial = DynamicImage::new_rgba8(1, 1);\n        initial.put_pixel(0, 0, Rgba::from([132, 3, 7, 200]));\n\n        let image = Image::from_dynamic(initial.clone(), true, RenderAssetUsages::RENDER_WORLD);\n\n        // NOTE: Fails if `is_srgb = false` or the dynamic image is of the type rgb8.","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_image/src/image_texture_conversion.rs#L190-L226","documentation":"IntoDynamicImageError::UninitializedImage is returned at the top of Image::try_into_dynamic (image_texture_conversion.rs:161-163) when self.data is None — the Image has no CPU-side bytes. This is the conversion-API twin of TextureAccessError::Uninitialized: the asset was loaded with RenderAssetUsages::RENDER_WORLD (CPU copy dropped after GPU upload) or otherwise constructed without data (Image::default / new_uninit). Bevy cannot produce a DynamicImage from texture bytes it no longer holds.","triggerScenarios":"Calling image.try_into_dynamic() on an image loaded with asset_usage = RenderAssetUsages::RENDER_WORLD; on Image::default(); on any image whose data field is None (e.g. after data was taken out with .data.take()).","commonSituations":"Screenshot/thumbnail code running on render-target images created RENDER_WORLD-only; memory-optimized builds that drop CPU copies; extracting a DynamicImage from a handle returned by the render pipeline rather than the original asset.","solutions":["Load/retain the texture with RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD (default) so data survives on CPU.","Check image.data.is_some() before calling try_into_dynamic and report a precise error.","If the image is RENDER_WORLD-only, re-request the original asset from the AssetServer instead of the GPU-side handle.","Never construct images you intend to convert with Image::default() or new_uninit without filling data."],"exampleFix":"// before\nserver.load_with_settings(\"photo.png\", |s: &mut ImageLoaderSettings| {\n    s.asset_usage = RenderAssetUsages::RENDER_WORLD;\n});\nlet dyn_img = image.try_into_dynamic()?; // Err(UninitializedImage)\n\n// after — keep MAIN_WORLD so data stays on CPU\ns.asset_usage = RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD;","handlingStrategy":"validation","validationCode":"// guard before converting\nif image.data.is_none() {\n    warn!(\"image has no CPU data (RENDER_WORLD-only?); cannot convert\");\n    return;\n}\nlet dyn_img = image.try_into_dynamic()?;","typeGuard":"fn convertible_now(image: &Image) -> bool {\n    image.data.is_some()\n        && matches!(\n            image.texture_descriptor.format,\n            TextureFormat::R8Unorm\n                | TextureFormat::Rg8Unorm\n                | TextureFormat::Rgba8UnormSrgb\n                | TextureFormat::Bgra8UnormSrgb\n                | TextureFormat::Bgra8Unorm\n        )\n}","tryCatchPattern":"match image.try_into_dynamic() {\n    Err(IntoDynamicImageError::UninitializedImage) => {\n        // re-load source with MAIN_WORLD usage, then retry\n    }\n    Err(IntoDynamicImageError::UnsupportedFormat(f)) => { /* convert format first */ }\n    Err(IntoDynamicImageError::UnknownConversionError(f)) => { /* fix data/extent mismatch */ }\n    Ok(dyn) => { /* ... */ }\n}","preventionTips":["Load images you plan to post-process with RenderAssetUsages::MAIN_WORLD included.","Avoid .data.take() on images you still need to convert.","Centralize DynamicImage extraction in one helper that checks data presence first."],"tags":["bevy","texture","render-asset-usages","dynamic-image","rust"],"backgroundTag":"cpu-texture-data-unavailable","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}