{"record":{"id":"e084708405fcd517","repo":"emilk/egui","slug":"error-parsing-ttf-otf-font-file-err","errorCode":null,"errorMessage":"Error parsing {:?} TTF/OTF font file: {err}","messagePattern":"Error parsing (.+?) TTF/OTF font file: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/epaint/src/text/family.rs","lineNumber":51,"sourceCode":"    face_cache: ahash::HashMap<char, FontFaceKey>,\n\n    /// Lazily calculated: every supported char, and the names of the faces that have it.\n    characters: Option<BTreeMap<char, Vec<String>>>,\n}\n\nimpl Family {\n    /// Install the fonts the providers want for `name` up front, in provider order.\n    pub fn new(name: &FontFamily, faces: &mut FaceStore, providers: &FontProviders) -> Self {\n        let mut chain: Vec<FontFaceKey> = Vec::new();\n        for insert in providers.fonts_for_family(name) {\n            match faces.install(&insert.name, &insert.data) {\n                Ok(key) => {\n                    if !chain.contains(&key) {\n                        chain.push(key);\n                    }\n                }\n                Err(err) => {\n                    panic!(\"Error parsing {:?} TTF/OTF font file: {err}\", insert.name);\n                }\n            }\n        }\n        if chain.is_empty() {\n            log::error!(\"No font provider has any font for FontFamily::{name:?}\");\n        }\n\n        Self {\n            name: name.clone(),\n            chain,\n            face_cache: Default::default(),\n            characters: None,\n        }\n    }\n\n    #[inline]\n    pub fn name(&self) -> &FontFamily {\n        &self.name","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/epaint/src/text/family.rs#L33-L69","documentation":"This panic occurs while building a `FontFamily`: when inserting font data, the library parses each TTF/OTF blob and if the parse fails (or the insertion into the font chain otherwise errors) it panics with the font name and the underlying error. Font parsing failure means the provided bytes are not a valid TrueType/OpenType font.","triggerScenarios":"Calling `FontFamily::new` (or `FontDefinitions` setup that feeds `FontInsert`s into the family chain) with font bytes that fail `FontData`/ab_glyph parsing — e.g. corrupted files, empty buffers, HTML/HTTP error pages saved as .ttf, or unsupported font formats (Type 1, WOFF without conversion).","commonSituations":"Bundled fonts corrupted by build tooling or git LFS placeholders not materialized; embedding fonts via `include_bytes!` from a mis-downloaded file; passing a WOFF2 web font where TTF is required; typo'd asset paths yielding wrong files.","solutions":["Verify the font bytes parse: open the file with `fonttools`/`otfinfo` or try loading it in another tool; re-download or replace the corrupt font.","Convert unsupported formats (WOFF/WOFF2) to TTF/OTF before embedding (e.g. `woff2_decompress`).","Ensure the file was fully downloaded/embedded — check for git LFS pointer files or truncated buffers (`data.len()` vs expected size).","Read the trailing `err` in the panic message; it names the specific parser complaint (bad magic number, missing tables) and points to the fix."],"exampleFix":"// before\nlet data = std::fs::read(\"assets/font.woff2\").unwrap();\nfont_definitions.families.entry(FontFamily::Proportional).or_default().push(\"MyFont\".to_owned());\nfont_definitions.font_data.insert(\"MyFont\".to_owned(), Cow::Owned(FontData::from_owned(data)));\n// after\nlet data = std::fs::read(\"assets/font.ttf\").expect(\"valid TTF\");\nassert!(FontData::from_owned(data.clone()).ttf.parsing_ok()); // validate before registering","handlingStrategy":"validation","validationCode":"// Validate font bytes before registering\nfn is_likely_font(data: &[u8]) -> bool {\n    data.len() >= 4 && matches!(&data[0..4], b\"\\x00\\x01\\x00\\x00\" | b\"OTTO\" | b\"true\" | b\"ttcf\")\n}","typeGuard":"fn valid_font_data(data: &[u8]) -> bool {\n    data.len() > 12\n        && (data.starts_with(&[0x00, 0x01, 0x00, 0x00]) || data.starts_with(b\"OTTO\"))\n}","tryCatchPattern":"// Panic cannot be caught; validate up front or parse in a fallible step first\nlet font = ab_glyph::FontArc::try_from_vec(data.clone()).map_err(|e| format!(\"bad font: {e}\"))?;\nfont_data.insert(name.to_owned(), Cow::Owned(FontData::from_owned(data)));","preventionTips":["Pre-parse fonts with `ab_glyph::FontArc::try_from_vec` before inserting into FontDefinitions.","Never embed WOFF/WOFF2 web fonts where TTF/OTF is expected; convert first.","Check bundled assets for git LFS pointer files or truncation in CI."],"tags":["fonts","panic","parsing","rust"],"backgroundTag":"schema-validation-failed","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}