{"record":{"id":"ecf52c05fc3f4415","repo":"flxzt/rnote","slug":"make-piet-image-in-bitmapimage-draw-impl-failed-e","errorCode":null,"errorMessage":"Make piet image in BitmapImage draw impl failed, Err: {e:?}","messagePattern":"Make piet image in BitmapImage draw impl failed, Err: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/strokes/bitmapimage.rs","lineNumber":64,"sourceCode":"    fn update_geometry(&mut self) {}\n}\n\nimpl Drawable for BitmapImage {\n    fn draw(&self, cx: &mut impl piet::RenderContext, _image_scale: f64) -> anyhow::Result<()> {\n        let piet_image_format = piet::ImageFormat::from(self.image.memory_format);\n\n        cx.save().map_err(|e| anyhow::anyhow!(\"{e:?}\"))?;\n        cx.transform(self.rectangle.affine.to_kurbo());\n\n        let piet_image = cx\n            .make_image(\n                self.image.pixel_width as usize,\n                self.image.pixel_height as usize,\n                &self.image.data,\n                piet_image_format,\n            )\n            .map_err(|e| {\n                anyhow::anyhow!(\"Make piet image in BitmapImage draw impl failed, Err: {e:?}\")\n            })?;\n        let dest_rect = self.rectangle.cuboid.local_aabb().to_kurbo_rect();\n        cx.draw_image(&piet_image, dest_rect, piet::InterpolationMode::Bilinear);\n        cx.restore().map_err(|e| anyhow::anyhow!(\"{e:?}\"))?;\n\n        Ok(())\n    }\n}\n\nimpl Shapeable for BitmapImage {\n    fn bounds(&self) -> Aabb {\n        self.rectangle.bounds()\n    }\n\n    fn hitboxes(&self) -> Vec<Aabb> {\n        vec![self.bounds()]\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/strokes/bitmapimage.rs#L46-L82","documentation":"During BitmapImage's piet draw, creating the piet Image from the raw PNG/JPEG pixel data (via PietContext::make_image with the stored width, height, and byte buffer) failed. This is a rendering-time failure: the embedded image bytes are invalid or incompatible with the piet/cairo backend, so the stroke cannot be rasterized onto the target surface.","triggerScenarios":"Rendering a BitmapImage stroke whose `image.data` bytes are corrupt, truncated, in an unexpected format, or whose pixel dimensions mismatch the buffer size; rendering after deserializing a document with a damaged embedded image; backend make_image limitations.","commonSituations":"Opening an .rnote document whose embedded PNG data was corrupted by a partial save/transfer; rendering to an unusual piet backend that rejects the image format; memory pressure producing truncated buffers.","solutions":["Validate the embedded image bytes (decode with an image library) before/while loading the document and repair or drop broken strokes.","Re-export or re-embed the image and re-save the document.","Check that pixel_width/pixel_height match the data buffer length and expected format (piet_image_format).","Update piet/cairo backend crates in case of a known make_image bug."],"exampleFix":"// before\ncx.make_image(w, h, &self.image.data, piet_image_format)?;\n// after\nlet piet_image = cx.make_image(w, h, &self.image.data, piet_image_format)\n    .with_context(|| format!(\"bad bitmap image {}x{} ({} bytes)\", w, h, self.image.data.len()))?;","handlingStrategy":"try-catch","validationCode":"// Rust: sanity-check the embedded image before rendering\nfn bitmap_image_renderable(img: &BitmapImage) -> bool {\n    !img.image.data.is_empty()\n        && img.image.pixel_width > 0\n        && img.image.pixel_height > 0\n        && image::load_from_memory(&img.image.data).is_ok()\n}","typeGuard":"fn has_valid_bitmap_data(img: &BitmapImage) -> bool {\n    matches!(image::load_from_memory(&img.image.data), Ok(_))\n}","tryCatchPattern":"match stroke.draw(&mut cx) {\n    Ok(()) => {},\n    Err(e) => log::warn!(\"skipping unrenderable bitmap stroke: {e:#}\"),\n}","preventionTips":["Validate embedded image bytes on document load and drop/repair corrupt strokes early.","Keep pixel dimensions consistent with the data buffer size when constructing BitmapImage.","Checksum embedded images at save time to detect corruption from partial writes."],"tags":["rust","rendering","piet","image"],"backgroundTag":"image-render-failed","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}