{"record":{"id":"b41b6806b0e5a68e","repo":"stride3d/stride","slug":"font","errorCode":null,"errorMessage":"font","messagePattern":"font","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/UIBatch.cs","lineNumber":431,"sourceCode":"                DepthBias = depthBias,\n                ColorScale = color,\n                ColorAdd = Color.Zero,\n                Swizzle = swizzle,\n                Primitive = PrimitiveType.Rectangle,\n                VertexShift = Vector4.Zero,\n                UnitXWorld = worldViewProjectionMatrix.Row1,\n                UnitYWorld = worldViewProjectionMatrix.Row2,\n                LeftTopCornerWorld = worldViewProjectionMatrix.Row4,\n            };\n\n            var elementInfo = new ElementInfo(4, 6, in drawInfo, depthBias);\n\n            Draw(texture, in elementInfo);\n        }\n\n        internal void DrawString([NotNull] SpriteFont font, [NotNull] string text, ref SpriteFont.InternalUIDrawCommand drawCommand)\n        {\n            if (font == null) throw new ArgumentNullException(nameof(font));\n            if (text == null) throw new ArgumentNullException(nameof(text));\n\n            var proxy = new SpriteFont.StringProxy(text);\n\n            // shift the string position so that it is written from the left/top corner of the element\n            var leftTopCornerOffset = drawCommand.TextBoxSize / 2;\n            var worldMatrix = drawCommand.Matrix;\n            worldMatrix.M41 -= worldMatrix.M11 * leftTopCornerOffset.X + worldMatrix.M21 * leftTopCornerOffset.Y;\n            worldMatrix.M42 -= worldMatrix.M12 * leftTopCornerOffset.X + worldMatrix.M22 * leftTopCornerOffset.Y;\n            worldMatrix.M43 -= worldMatrix.M13 * leftTopCornerOffset.X + worldMatrix.M23 * leftTopCornerOffset.Y;\n\n            // transform the world matrix into the world view project matrix\n            Matrix.Multiply(ref worldMatrix, ref viewProjectionMatrix, out drawCommand.Matrix);\n\n            font.TypeSpecificRatios(drawCommand.RequestedFontSize, ref drawCommand.SnapText, ref drawCommand.RealVirtualResolutionRatio, out var actualFontSize);\n\n            // snap draw start position to prevent characters to be drawn in between two pixels\n            if (drawCommand.SnapText)","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/UIBatch.cs#L413-L449","documentation":"Thrown by UIBatch.DrawString when the font parameter is null. DrawString requires a valid SpriteFont to render text, so a null font is rejected with ArgumentNullException before the string proxy is built. (The same method also throws for a null text argument.)","triggerScenarios":"Calling DrawString(null, text, ref drawCommand) — commonly a UI text element whose Font property was never assigned or whose font asset failed to load.","commonSituations":"Missing font asset reference in a scene/UI component; asynchronous font load not completed; serialized field left unset; font deleted from assets.","solutions":["Assign a valid SpriteFont to the text element (e.g. in the UI editor or via code) before drawing.","Null-check font at the call site and skip rendering or substitute a default font.","Verify the font asset loads successfully and is not null after load."],"exampleFix":"// before\nuiBatch.DrawString(textElement.Font, textElement.Text, ref drawCommand);\n// after\nif (textElement.Font != null && textElement.Text != null)\n    uiBatch.DrawString(textElement.Font, textElement.Text, ref drawCommand);","handlingStrategy":"validation","validationCode":"if (font == null || string.IsNullOrEmpty(text)) return;","typeGuard":"bool CanDrawText(SpriteFont f, string s) => f != null && !string.IsNullOrEmpty(s);","tryCatchPattern":"try { uiBatch.DrawString(font, text, ref cmd); }\ncatch (ArgumentNullException e) when (e.ParamName == \"font\" || e.ParamName == \"text\") { log.Warning(\"DrawString skipped\", e); }","preventionTips":["Assign font assets in the UI editor and validate on load.","Fall back to a default font when the primary asset is missing.","Check null/empty text before batching each frame."],"tags":["ui","null-argument","font"],"backgroundTag":"null-argument","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"}