{"record":{"id":"c50766c2cb441a51","repo":"stride3d/stride","slug":"tried-to-compile-a-dynamic-sprite-font-with-compiler-for-c50766","errorCode":null,"errorMessage":"Tried to compile a dynamic sprite font with compiler for signed distance field fonts","messagePattern":"Tried to compile a dynamic sprite font with compiler for signed distance field fonts","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Assets/SpriteFont/Compiler/SignedDistanceFieldFontCompiler.cs","lineNumber":107,"sourceCode":"\nnamespace Stride.Assets.SpriteFont.Compiler\n{\n    /// <summary>\n    /// Main class used to compile a Font file XML file.\n    /// </summary>\n    public class SignedDistanceFieldFontCompiler\n    {\n        /// <summary>\n        /// Compiles the specified font description into a <see cref=\"SignedDistanceFieldSpriteFont\" /> object.\n        /// </summary>\n        /// <param name=\"fontFactory\">The font factory used to create the fonts</param>\n        /// <param name=\"fontAsset\">The font description.</param>\n        /// <returns>A SpriteFontData object.</returns>\n        public static Graphics.SpriteFont Compile(IFontFactory fontFactory, SpriteFontAsset fontAsset)\n        {\n            var fontTypeSDF = fontAsset.FontType as SignedDistanceFieldSpriteFontType;\n            if (fontTypeSDF == null)\n                throw new ArgumentException(\"Tried to compile a dynamic sprite font with compiler for signed distance field fonts\");\n\n            float lineSpacing;\n            float baseLine;\n\n            var glyphs = ImportFont(fontAsset, out lineSpacing, out baseLine);\n\n            Image<Rgba32> bitmap = GlyphPacker.ArrangeGlyphs(glyphs);\n\n            return SignedDistanceFieldFontWriter.CreateSpriteFontData(fontFactory, fontAsset, glyphs, lineSpacing, baseLine, bitmap);\n        }\n\n        static Glyph[] ImportFont(SpriteFontAsset options, out float lineSpacing, out float baseLine)\n        {\n            // Which importer knows how to read this source font?\n            IFontImporter importer;\n\n            var sourceExtension = (Path.GetExtension(options.FontSource.GetFontPath()) ?? \"\").ToLowerInvariant();\n            var bitmapFileExtensions = new List<string> { \".bmp\", \".png\", \".gif\" };","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/SpriteFont/Compiler/SignedDistanceFieldFontCompiler.cs#L89-L125","documentation":"SignedDistanceFieldFontCompiler.Compile only accepts SpriteFontAssets whose FontType is SignedDistanceFieldSpriteFontType. Any other FontType — including dynamic sprite font types — makes the cast fail and throws this ArgumentException. The compiler is SDF-specific and cannot process assets configured for other pipelines.","triggerScenarios":"Calling SignedDistanceFieldFontCompiler.Compile(fontFactory, fontAsset) where `fontAsset.FontType as SignedDistanceFieldSpriteFontType` returns null — e.g. an OfflineRasterizedSpriteFontType or dynamic font asset.","commonSituations":"Pointing the SDF compiler at a legacy rasterized font asset; build scripts that compile all fonts with one compiler regardless of FontType; pre-SDF assets whose FontType was never migrated.","solutions":["Set the asset's FontType to SignedDistanceFieldSpriteFontType before calling the SDF compiler.","Route offline-rasterized assets to OfflineRasterizedFontCompiler — always use the compiler matching the FontType.","Add a FontType switch in build tooling to pick the correct compiler per asset.","Inspect the font asset definition and correct the FontType element."],"exampleFix":"// before\nSignedDistanceFieldFontCompiler.Compile(factory, rasterizedAsset); // throws\n// after\nswitch (asset.FontType)\n{\n    case SignedDistanceFieldSpriteFontType: SignedDistanceFieldFontCompiler.Compile(factory, asset); break;\n    case OfflineRasterizedSpriteFontType: OfflineRasterizedFontCompiler.Compile(factory, asset); break;\n}","handlingStrategy":"type-guard","validationCode":"if (fontAsset?.FontType is not SignedDistanceFieldSpriteFontType)\n    throw new InvalidOperationException(\"SignedDistanceFieldFontCompiler requires a SignedDistanceFieldSpriteFontType asset\");","typeGuard":"bool IsSdfFont(SpriteFontAsset asset) => asset?.FontType is SignedDistanceFieldSpriteFontType;","tryCatchPattern":"try\n{\n    var font = SignedDistanceFieldFontCompiler.Compile(factory, fontAsset);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"dynamic sprite font\"))\n{\n    // wrong pipeline: re-dispatch based on FontType\n    font = CompileWithMatchingCompiler(factory, fontAsset);\n}","preventionTips":["Route each font asset to the compiler matching its FontType.","Add a FontType switch at the single place build tooling dispatches to compilers.","Migrate legacy rasterized assets explicitly before using SDF compilation.","Review asset definitions after upgrades so FontType values remain valid."],"tags":["fonts","sdf","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}