emilk/egui · critical

Error parsing {:?} TTF/OTF font file: {err}

Error message

Error parsing {:?} TTF/OTF font file: {err}

What it means

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.

Source

Thrown at crates/epaint/src/text/family.rs:51

    face_cache: ahash::HashMap<char, FontFaceKey>,

    /// Lazily calculated: every supported char, and the names of the faces that have it.
    characters: Option<BTreeMap<char, Vec<String>>>,
}

impl Family {
    /// Install the fonts the providers want for `name` up front, in provider order.
    pub fn new(name: &FontFamily, faces: &mut FaceStore, providers: &FontProviders) -> Self {
        let mut chain: Vec<FontFaceKey> = Vec::new();
        for insert in providers.fonts_for_family(name) {
            match faces.install(&insert.name, &insert.data) {
                Ok(key) => {
                    if !chain.contains(&key) {
                        chain.push(key);
                    }
                }
                Err(err) => {
                    panic!("Error parsing {:?} TTF/OTF font file: {err}", insert.name);
                }
            }
        }
        if chain.is_empty() {
            log::error!("No font provider has any font for FontFamily::{name:?}");
        }

        Self {
            name: name.clone(),
            chain,
            face_cache: Default::default(),
            characters: None,
        }
    }

    #[inline]
    pub fn name(&self) -> &FontFamily {
        &self.name

View on GitHub (pinned to 441971a776)

Solutions

  1. 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.
  2. Convert unsupported formats (WOFF/WOFF2) to TTF/OTF before embedding (e.g. `woff2_decompress`).
  3. Ensure the file was fully downloaded/embedded — check for git LFS pointer files or truncated buffers (`data.len()` vs expected size).
  4. Read the trailing `err` in the panic message; it names the specific parser complaint (bad magic number, missing tables) and points to the fix.

Example fix

// before
let data = std::fs::read("assets/font.woff2").unwrap();
font_definitions.families.entry(FontFamily::Proportional).or_default().push("MyFont".to_owned());
font_definitions.font_data.insert("MyFont".to_owned(), Cow::Owned(FontData::from_owned(data)));
// after
let data = std::fs::read("assets/font.ttf").expect("valid TTF");
assert!(FontData::from_owned(data.clone()).ttf.parsing_ok()); // validate before registering
Defensive patterns

Strategy: validation

Validate before calling

// Validate font bytes before registering
fn is_likely_font(data: &[u8]) -> bool {
    data.len() >= 4 && matches!(&data[0..4], b"\x00\x01\x00\x00" | b"OTTO" | b"true" | b"ttcf")
}

Type guard

fn valid_font_data(data: &[u8]) -> bool {
    data.len() > 12
        && (data.starts_with(&[0x00, 0x01, 0x00, 0x00]) || data.starts_with(b"OTTO"))
}

Try / catch

// Panic cannot be caught; validate up front or parse in a fallible step first
let font = ab_glyph::FontArc::try_from_vec(data.clone()).map_err(|e| format!("bad font: {e}"))?;
font_data.insert(name.to_owned(), Cow::Owned(FontData::from_owned(data)));

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of emilk/egui@441971a776 (2026-09-12). Data as JSON: /api/errors/e084708405fcd517. Report an issue: GitHub.