{"record":{"id":"812f0de8d88c13cf","repo":"slint-ui/slint","slug":"embedtextures-builds-the-shared-font-collection","errorCode":null,"errorMessage":"EmbedTextures builds the shared font collection","messagePattern":"EmbedTextures builds the shared font collection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/passes.rs","lineNumber":360,"sourceCode":"            doc.visit_all_used_components(|component| {\n                embed_glyphs::collect_font_sizes_used(component, sf, &mut font_pixel_sizes);\n                embed_glyphs::collect_font_weights_used(component, &mut font_weights);\n                embed_glyphs::scan_string_literals(component, &mut characters_seen);\n            });\n\n            // This is not perfect, as this includes translations that may not be used.\n            #[cfg(feature = \"bundle-translations\")]\n            if let Some(translation_builder) = doc.translation_builder.as_ref() {\n                translation_builder.collect_characters_seen(&mut characters_seen);\n            }\n\n            embed_glyphs::embed_glyphs(\n                doc,\n                &type_loader.compiler_config,\n                font_pixel_sizes,\n                font_weights,\n                characters_seen,\n                font_collection.as_ref().expect(\"EmbedTextures builds the shared font collection\"),\n                diag,\n            );\n        }\n        _ => {\n            // Create font registration calls for custom fonts, unless we're embedding pre-rendered glyphs\n            collect_custom_fonts::collect_custom_fonts(\n                doc,\n                std::iter::once(&*doc).chain(type_loader.all_documents()),\n                type_loader.compiler_config.embed_resources\n                    == crate::EmbedResourcesKind::EmbedAllResources,\n            );\n        }\n    };\n\n    raw_type_loader\n}\n\n/// Run the passes on imported documents","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/compiler/passes.rs#L342-L378","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["If you don't need pre-rendered glyph textures, switch `embed_resources` to `EmbedTexturesOnlyAsPreRendered` fallback or `EmbedFonts`/`DoNotEmbed` in `CompilerConfiguration`.","Ensure the document/register fonts so the font collection gets populated before glyph embedding.","Upgrade to the latest stable Slint compiler to rule out a pass-ordering regression.","Contributors: guarantee `font_collection` is built whenever the `EmbedTextures` match arm is entered."],"exampleFix":"// before (Rust, slint-build)\nconfig.embed_resources = EmbedResources::EmbedTextures;\n// after\nconfig.embed_resources = EmbedResources::EmbedFonts;","handlingStrategy":"fallback","validationCode":"// in slint-build scripts: pick a safe embedding mode\nif font_files.iter().any(huge_or_unusual) {\n    config.embed_resources = EmbedResources::EmbedFonts; // instead of EmbedTextures\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use EmbedTextures when your build actually populates the font collection (registers fonts/text).","Include at least one text element/font reference so fonts are collected.","Keep compiler pass code so font_collection is unconditionally built in the EmbedTextures arm."],"tags":["rust","compiler","internal-panic","fonts"],"backgroundTag":"internal-invariant-violation","analyzedSha":"3a7e700487dc74d404cad0726378053ab763d4e0","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}