{"record":{"id":"db19c9634e93dd08","repo":"stride3d/stride","slug":"text-uibatch","errorCode":null,"errorMessage":"text","messagePattern":"text","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/UIBatch.cs","lineNumber":432,"sourceCode":"                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)\n            {","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/UIBatch.cs#L414-L450","documentation":"UIBatch.DrawString throws ArgumentNullException when either the SpriteFont or the text string passed to it is null. The library requires a valid font and a non-null string to render text into the UI batch; null values cannot be drawn. This is a fast-fail guard placed at the start of the draw call so failures surface at the call site rather than deep inside batch rendering.","triggerScenarios":"Calling DrawString(spriteFont, text, ref drawCommand) with a font variable that was never loaded (null) or with a text argument that is null, e.g. reading a UI label from a data source that returned null.","commonSituations":"Font assets missing from the build/content database so the font field stays null; a game data table or localization file with an absent value deserialized as null; refactoring away an initialization that used to assign the font.","solutions":["Ensure the SpriteFont is loaded before drawing: font = Content.Load<SpriteFont>(\"MyFont\") and verify it is not null","Replace null text with string.Empty or a placeholder before calling DrawString","Add an early guard in the calling code: if (font == null || text == null) return; or throw a descriptive error","Check that the font asset is included in the project's asset compilation so loading succeeds"],"exampleFix":"// before\nbatch.DrawString(font, labelText, ref drawCommand);\n// after\nif (font != null && labelText != null)\n    batch.DrawString(font, labelText, ref drawCommand);","handlingStrategy":"type-guard","validationCode":"if (font == null) throw new InvalidOperationException(\"UI font not loaded\");\nif (text == null) text = string.Empty;","typeGuard":"static bool CanDraw(SpriteFont font, string text) => font != null && text != null;","tryCatchPattern":"try { batch.DrawString(font, text, ref cmd); }\ncatch (ArgumentNullException ex) { logger.Warn($\"Skipped text draw: {ex.ParamName} is null\"); }","preventionTips":["Load fonts during initialization and fail fast if Content.Load returns null","Use string.Empty as the default for UI label fields instead of null","Enable nullable reference types to catch unassigned font fields at compile time"],"tags":["csharp","graphics","ui","null-check"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}