slint-ui/slint · error

EmbedTextures builds the shared font collection

Error message

EmbedTextures builds the shared font collection

What it means

This panic fires in `run_passes` (internal/compiler/passes.rs:359) when calling `embed_glyphs` in the `EmbedTextures` resource-embedding mode. The shared `font_collection` is expected to have been built earlier in the same pass (`EmbedTextures` mode builds it), but if it is `None`, the invariant 'EmbedTextures builds the shared font collection' is broken and the compiler panics.

Solutions

  1. If you don't need pre-rendered glyph textures, switch `embed_resources` to `EmbedTexturesOnlyAsPreRendered` fallback or `EmbedFonts`/`DoNotEmbed` in `CompilerConfiguration`.
  2. Ensure the document/register fonts so the font collection gets populated before glyph embedding.
  3. Upgrade to the latest stable Slint compiler to rule out a pass-ordering regression.
  4. Contributors: guarantee `font_collection` is built whenever the `EmbedTextures` match arm is entered.

Example fix

// before (Rust, slint-build)
config.embed_resources = EmbedResources::EmbedTextures;
// after
config.embed_resources = EmbedResources::EmbedFonts;
Defensive patterns

Strategy: fallback

Validate before calling

// in slint-build scripts: pick a safe embedding mode
if font_files.iter().any(huge_or_unusual) {
    config.embed_resources = EmbedResources::EmbedFonts; // instead of EmbedTextures
}

Prevention

When it happens

Trigger: Compiling with `compiler_config.embed_resources == EmbedResources::EmbedTextures` when the font collection was not initialized — e.g. no fonts were collected because the document contains no text elements/font references, a pass-ordering regression, or a custom build altered the font collection setup.

Common situations: Embedded targets using `EmbedTextures` (pre-rendered texture glyphs) via the Slint compiler config; CI/embedded builds with unusual font setups; contributor changes to `collect_custom_fonts`/font collection initialization.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16). Data as JSON: /api/errors/812f0de8d88c13cf. Report an issue: GitHub.

Appendix: source

Thrown at internal/compiler/passes.rs:360

            doc.visit_all_used_components(|component| {
                embed_glyphs::collect_font_sizes_used(component, sf, &mut font_pixel_sizes);
                embed_glyphs::collect_font_weights_used(component, &mut font_weights);
                embed_glyphs::scan_string_literals(component, &mut characters_seen);
            });

            // This is not perfect, as this includes translations that may not be used.
            #[cfg(feature = "bundle-translations")]
            if let Some(translation_builder) = doc.translation_builder.as_ref() {
                translation_builder.collect_characters_seen(&mut characters_seen);
            }

            embed_glyphs::embed_glyphs(
                doc,
                &type_loader.compiler_config,
                font_pixel_sizes,
                font_weights,
                characters_seen,
                font_collection.as_ref().expect("EmbedTextures builds the shared font collection"),
                diag,
            );
        }
        _ => {
            // Create font registration calls for custom fonts, unless we're embedding pre-rendered glyphs
            collect_custom_fonts::collect_custom_fonts(
                doc,
                std::iter::once(&*doc).chain(type_loader.all_documents()),
                type_loader.compiler_config.embed_resources
                    == crate::EmbedResourcesKind::EmbedAllResources,
            );
        }
    };

    raw_type_loader
}

/// Run the passes on imported documents

View on GitHub (pinned to 3a7e700487)