{"record":{"id":"cdc0ba4b7b46d41c","repo":"stride3d/stride","slug":"tried-to-compile-a-dynamic-sprite-font-with-compiler-for-cdc0ba","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/OfflineRasterizedFontCompiler.cs","lineNumber":204,"sourceCode":"                        break;\n                    }\n                }\n                if (!defaultCharacterFound)\n                {\n                    throw new InvalidOperationException(\"The specified DefaultCharacter is not part of this font.\");\n                }\n            }\n\n            return glyphs.ToArray();\n        }\n\n        public static List<char> GetCharactersToImport(SpriteFontAsset asset)\n        {\n            var characters = new List<char>();\n\n            var fontTypeStatic = asset.FontType as OfflineRasterizedSpriteFontType;\n            if (fontTypeStatic == null)\n                throw new ArgumentException(\"Tried to compile a dynamic sprite font with compiler for signed distance field fonts\");\n\n            // extract the list from the provided file if it exits\n            if (File.Exists(fontTypeStatic.CharacterSet))\n            {\n                string text;\n                using (var streamReader = new StreamReader(fontTypeStatic.CharacterSet, Encoding.UTF8))\n                    text = streamReader.ReadToEnd();\n                characters.AddRange(text);\n            }\n\n            // add character coming from character ranges\n            characters.AddRange(CharacterRegion.Flatten(fontTypeStatic.CharacterRegions));\n\n            // remove duplicated characters\n            characters = characters.Distinct().ToList();\n\n            return characters;\n        }","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/SpriteFont/Compiler/OfflineRasterizedFontCompiler.cs#L186-L222","documentation":"GetCharactersToImport in OfflineRasterizedFontCompiler only accepts a SpriteFontAsset whose FontType is OfflineRasterizedSpriteFontType. Passing an asset configured for another pipeline (dynamic sprite font or SDF) makes the cast fail and throws this ArgumentException. Despite the message text mentioning signed distance field fonts, the real condition is simply: the FontType is not the offline rasterized type.","triggerScenarios":"Invoking OfflineRasterizedFontCompiler.GetCharactersToImport or Compile with a SpriteFontAsset whose FontType is a dynamic sprite font type or SignedDistanceFieldSpriteFontType instead of OfflineRasterizedSpriteFontType.","commonSituations":"Mixing dynamic and static (offline-rasterized) font assets in build scripts; an asset whose FontType was changed to dynamic but still routed through the offline compiler; programmatic font asset generation assigning the wrong FontType subclass.","solutions":["Set the asset's FontType to OfflineRasterizedSpriteFontType (with a CharacterSet file or character regions) before compiling offline.","If you want a dynamic font, do not run it through OfflineRasterizedFontCompiler — dynamic fonts are built at runtime, not by this asset compiler.","Audit the asset definition and make sure the FontType element matches the compiler being invoked.","In tooling code, type-check `asset.FontType is OfflineRasterizedSpriteFontType` before calling."],"exampleFix":"// before\nasset.FontType = new DynamicSpriteFontType();\nvar chars = OfflineRasterizedFontCompiler.GetCharactersToImport(asset);\n// after\nasset.FontType = new OfflineRasterizedSpriteFontType { CharacterSet = \"charset.txt\" };\nvar chars = OfflineRasterizedFontCompiler.GetCharactersToImport(asset);","handlingStrategy":"type-guard","validationCode":"if (asset?.FontType is not OfflineRasterizedSpriteFontType)\n    throw new InvalidOperationException(\"OfflineRasterizedFontCompiler requires an OfflineRasterizedSpriteFontType asset\");","typeGuard":"bool CanCompileOffline(SpriteFontAsset asset) => asset?.FontType is OfflineRasterizedSpriteFontType;","tryCatchPattern":"try\n{\n    var chars = OfflineRasterizedFontCompiler.GetCharactersToImport(asset);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"dynamic sprite font\"))\n{\n    logger.LogWarning(\"Asset {Name} is not offline-rasterizable; routing to dynamic pipeline\", asset.Name);\n    // build/compile the font at runtime instead\n}","preventionTips":["Match compiler to FontType: offline compiler for OfflineRasterizedSpriteFontType, SDF compiler for SDF types.","Never route dynamic (runtime) fonts through offline asset compilers.","Use a switch on FontType in build tooling instead of assuming one compiler fits all.","Keep font asset templates consistent so FontType is not accidentally changed."],"tags":["fonts","assets","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"}