{"record":{"id":"d06bdba4ee0d8b0a","repo":"flxzt/rnote","slug":"building-text-layout-failed-err-e","errorCode":null,"errorMessage":"Building text layout failed, Err: {e:?}","messagePattern":"Building text layout failed, Err: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/strokes/textstroke.rs","lineNumber":348,"sourceCode":"        cursor: &GraphemeCursor,\n    ) -> anyhow::Result<piet::HitTestPosition>\n    where\n        T: piet::Text,\n    {\n        let text_layout = self.build_text_layout(piet_text, text)?;\n\n        Ok(text_layout.hit_test_text_position(cursor.cur_cursor()))\n    }\n\n    pub fn get_selection_rects_for_cursors(\n        &self,\n        text: String,\n        cursor: &GraphemeCursor,\n        selection_cursor: &GraphemeCursor,\n    ) -> anyhow::Result<Vec<kurbo::Rect>> {\n        let text_layout = self\n            .build_text_layout(&mut piet_cairo::CairoText::new(), text)\n            .map_err(|e| anyhow::anyhow!(\"Building text layout failed, Err: {e:?}\"))?;\n\n        let range = if selection_cursor.cur_cursor() >= cursor.cur_cursor() {\n            cursor.cur_cursor()..selection_cursor.cur_cursor()\n        } else {\n            selection_cursor.cur_cursor()..cursor.cur_cursor()\n        };\n\n        Ok(text_layout.rects_for_range(range))\n    }\n\n    /// Draw the cursor.\n    pub fn draw_cursor(\n        &self,\n        cx: &mut impl piet::RenderContext,\n        text: String,\n        cursor: &GraphemeCursor,\n        affine: &DAffine2,\n        camera: &Camera,","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/strokes/textstroke.rs#L330-L366","documentation":"get_selection_rects_for_cursors first builds a text layout via build_text_layout; any layout failure is re-wrapped with this message. It is the same piet BuildError family as error 144, surfaced specifically while computing selection rectangles for drawing the text selection highlight.","triggerScenarios":"draw_text_selection requesting selection rects when the layout cannot be built — unavailable font family in the text style, or text state changed such that attributes/ranges are invalid.","commonSituations":"Rendering selections in text whose font was uninstalled since the file was saved; headless rendering where no fonts are available.","solutions":["Resolve the underlying font/layout issue (install or substitute the missing font)","Catch the error in draw_text_selection and skip drawing the selection for that frame instead of failing the render pass","Cache a fallback layout built with a guaranteed default family","Ensure attribute ranges are recomputed whenever the text string changes before selection queries"],"exampleFix":"// before\nlet text_layout = self.build_text_layout(&mut piet_cairo::CairoText::new(), text)\n    .map_err(|e| anyhow!(\"Building text layout failed, Err: {e:?}\"))?;\n// after\nlet text_layout = match self.build_text_layout(&mut piet_cairo::CairoText::new(), text) {\n    Ok(l) => l,\n    Err(e) => { log::warn!(\"selection layout failed: {e:?}\"); return Ok(Vec::new()); }\n};","handlingStrategy":"try-catch","validationCode":"let n = text.len();\nlet range_ok = cursor.cur_cursor() <= n && selection_cursor.cur_cursor() <= n;\nif !range_ok { return Ok(Vec::new()); }","typeGuard":null,"tryCatchPattern":"match stroke.get_selection_rects_for_cursors(piet, text, cursor, sel) {\n    Ok(rects) => rects,\n    Err(e) => { log::warn!(\"selection rendering skipped: {e:?}\"); Vec::new() }\n}","preventionTips":["Treat selection rendering as non-fatal: skip the highlight on layout failure","Rebuild cursors whenever the text content changes so cursor offsets stay valid","Ensure fonts resolve before enabling text selection rendering"],"tags":["piet","text-layout","selection","rendering"],"backgroundTag":"text-layout-build-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"}