{"record":{"id":"31561de4a5b7775f","repo":"stride3d/stride","slug":"tried-to-compile-a-dynamic-sprite-font-with-compiler-for","errorCode":null,"errorMessage":"Tried to compile a dynamic sprite font with compiler for static fonts","messagePattern":"Tried to compile a dynamic sprite font with compiler for static fonts","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Assets/SpriteFont/Compiler/OfflineRasterizedFontCompiler.cs","lineNumber":108,"sourceCode":"namespace Stride.Assets.SpriteFont.Compiler\n{\n    /// <summary>\n    /// Main class used to compile a Font file XML file.\n    /// </summary>\n    public class OfflineRasterizedFontCompiler\n    {\n        /// <summary>\n        /// Compiles the specified font description into a <see cref=\"OfflineRasterizedSpriteFont\" /> 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        /// <param name=\"srgb\"></param>\n        /// <returns>A SpriteFontData object.</returns>\n        public static Graphics.SpriteFont Compile(IFontFactory fontFactory, SpriteFontAsset fontAsset, bool srgb)\n        {\n            var fontTypeStatic = fontAsset.FontType as OfflineRasterizedSpriteFontType;\n            if (fontTypeStatic == null)\n                throw new ArgumentException(\"Tried to compile a dynamic sprite font with compiler for static fonts\");\n\n            float lineSpacing;\n            float baseLine;\n\n            var glyphs = ImportFont(fontAsset, out lineSpacing, out baseLine);\n\n            // Optimize.\n            foreach (Glyph glyph in glyphs)\n                GlyphCropper.Crop(glyph);\n\n            Image<Rgba32> bitmap = GlyphPacker.ArrangeGlyphs(glyphs);\n\n            // Automatically detect whether this is a monochromatic or color font?\n            //if (fontAsset.Format == FontTextureFormat.Auto)\n            //{\n            //    bool isMono = BitmapUtils.IsRgbEntirely(Color.White, bitmap);\n            //\n            //    fontAsset.Format = isMono ? FontTextureFormat.CompressedMono :","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/SpriteFont/Compiler/OfflineRasterizedFontCompiler.cs#L90-L126","documentation":"OfflineRasterizedFontCompiler.Compile casts fontAsset.FontType to OfflineRasterizedSpriteFontType; if the cast returns null the asset uses a dynamic (runtime-rasterized) font type, which this static compiler cannot handle, so an ArgumentException is thrown.","triggerScenarios":"Calling OfflineRasterizedFontCompiler.Compile with a SpriteFontAsset whose FontType is a dynamic font type (e.g. DynamicSpriteFontType) instead of OfflineRasterizedSpriteFontType.","commonSituations":"Custom build pipelines that route all sprite fonts through the offline compiler without checking FontType; switching a font asset from static to dynamic and reusing old compile code.","solutions":["Use the appropriate compiler for dynamic fonts (dynamic font factory/runtime path).","Check fontAsset.FontType is OfflineRasterizedSpriteFontType before calling this compiler.","Change the asset's font type to offline-rasterized if static compilation is intended."],"exampleFix":"// before\nOfflineRasterizedFontCompiler.Compile(factory, dynamicFontAsset, srgb);\n\n// after\nif (dynamicFontAsset.FontType is OfflineRasterizedSpriteFontType)\n    OfflineRasterizedFontCompiler.Compile(factory, dynamicFontAsset, srgb);\nelse\n    DynamicSpriteFontCompiler.Compile(factory, dynamicFontAsset, srgb);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"bool CanCompileOffline(SpriteFontAsset asset) => asset.FontType is OfflineRasterizedSpriteFontType;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"dynamic sprite font\")) { /* route to dynamic compiler */ }","preventionTips":["Branch on FontType before selecting a compiler.","Keep a single factory method that dispatches static vs dynamic fonts."],"tags":["fonts","type-mismatch","compiler"],"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"}