{"record":{"id":"615b3cb191b4f89c","repo":"stride3d/stride","slug":"failed-to-load-font-fontpath-freetype-error-err-fontmanager","errorCode":null,"errorMessage":"Failed to load font '{fontPath}' (FreeType error {err})","messagePattern":"Failed to load font '(.+?)' \\(FreeType error (.+?)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Font/FontManager.cs","lineNumber":349,"sourceCode":"                fontStream.ReadExactly(fontData);\n\n                var handle = GCHandle.Alloc(fontData, GCHandleType.Pinned);\n                lock (freetypeLock)\n                {\n                    // Double-check inside lock\n                    if (cachedFontFaces.ContainsKey(fontPath))\n                    {\n                        handle.Free();\n                        return;\n                    }\n\n                    fixed (byte* ptr = fontData)\n                    {\n                        int err = FreeTypeNative.FT_New_Memory_Face(freetypeLibrary, ptr, new CLong(fontData.Length), new CLong(0), out FT_FaceRec* face);\n                        if (err != 0)\n                        {\n                            handle.Free();\n                            throw new InvalidOperationException($\"Failed to load font '{fontPath}' (FreeType error {err})\");\n                        }\n                        cachedFontFaces[fontPath] = ((nint)face, handle);\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Thread function in charge of building the bitmap\n        /// </summary>\n        private void BuildBitmapThread()\n        {\n            while (!bitmapShouldEndThread)\n            {\n                bitmapBuildSignal.WaitOne();\n\n                while (bitmapsToGenerate.Count > 0)\n                {","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Font/FontManager.cs#L331-L367","documentation":"LoadFontInMemory (invoked via GetOrCreateFontFace) passes a byte buffer to FT_New_Memory_Face; a nonzero result means FreeType rejected the embedded font data. The thrown InvalidOperationException names the font path and FreeType error code, and frees the pinned handle before throwing.","triggerScenarios":"GetOrCreateFontFace resolving a font whose loaded byte data is invalid: corrupted embedded font resource, wrong index/data slice, or data that FreeType cannot parse as a face.","commonSituations":"Embedded font resources corrupted during build (bad resx/embedded-resource step); passing a non-font stream (e.g. a license txt) to a runtime font loader; partial writes to a font cache file that is later reloaded.","solutions":["Confirm the bytes handed to the loader are the complete font file (compare hash with the source file)","Regenerate the embedded font resource; check the build task that embeds it","Match the FreeType error code in the message against FreeType error enums to pinpoint format issues","Clear any cached font data/cache files so a corrupt cache entry is rebuilt"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (fontBytes == null || fontBytes.Length < 12)\n    throw new InvalidDataException(\"Embedded font data is missing or truncated\");","typeGuard":null,"tryCatchPattern":"try { face = GetOrCreateFontFace(fontPath); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"FreeType error\"))\n{\n    log.Error($\"Failed to create font face for {fontPath}\", ex);\n    face = GetOrCreateFontFace(DefaultFontPath);\n}","preventionTips":["Hash-verify embedded font resources at build time","Never cache partially written font data; write atomically then rename","Validate embedded resource names/sizes after build"],"tags":["fonts","freetype","embedded-resources"],"backgroundTag":"file-read-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}