{"record":{"id":"032865018b5faec2","repo":"stride3d/stride","slug":"text","errorCode":null,"errorMessage":"text","messagePattern":"text","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/SpriteBatch.cs","lineNumber":488,"sourceCode":"        {\n            var proxy = new SpriteFont.StringProxy(text);\n            DrawString(spriteFont, ref proxy, fontSize, ref position, ref color, rotation, ref origin, ref scale, effects, layerDepth, alignment);\n        }\n\n        private void DrawString(SpriteFont spriteFont, ref SpriteFont.StringProxy text, float fontSize, ref Vector2 position, ref Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment)\n        {\n            DrawString(spriteFont, ref text, fontSize, ref position, ref color, rotation, ref origin, ref scale, effects, layerDepth, alignment);\n        }\n\n        private void DrawString(SpriteFont spriteFont, ref SpriteFont.StringProxy text, float fontSize, ref Vector2 position, ref Color4 color, float rotation, ref Vector2 origin, ref Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment)\n        {\n            if (spriteFont == null)\n            {\n                throw new ArgumentNullException(\"spriteFont\");\n            }\n            if (text.IsNull)\n            {\n                throw new ArgumentNullException(\"text\");\n            }\n            if (fontSize < 0)\n                fontSize = spriteFont.Size;\n\n            // calculate the resolution ratio between the screen real size and the virtual resolution\n            var commandList = GraphicsContext.CommandList;\n            var viewportSize = commandList.Viewport;\n            var virtualResolution = GetCurrentResolution(commandList);\n            var resolutionRatio = new Vector2(viewportSize.Width / virtualResolution.X, viewportSize.Height / virtualResolution.Y);\n            scale.X = scale.X / resolutionRatio.X;\n            scale.Y = scale.Y / resolutionRatio.Y;\n\n            var fontSize2 = fontSize * ((spriteFont.FontType == SpriteFontType.Dynamic) ? resolutionRatio : Vector2.One);\n            var drawCommand = new SpriteFont.InternalDrawCommand(this, in fontSize2, in position, in color, rotation, in origin, in scale, effects, layerDepth);\n\n            // snap the position the closest 'real' pixel\n            Vector2.Modulate(ref drawCommand.Position, ref resolutionRatio, out drawCommand.Position);\n            drawCommand.Position.X = MathF.Round(drawCommand.Position.X);","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/SpriteBatch.cs#L470-L506","documentation":"SpriteBatch.DrawString throws ArgumentNullException when the text argument is null (checked via StringProxy.IsNull). An empty string is allowed; only null is rejected, since the renderer cannot iterate a null text buffer. Fail-fast validation at the public entry point.","triggerScenarios":"Passing a C# null string/StringBuilder (or a StringProxy whose internal buffer is null) to any DrawString overload — e.g. building the text from a null result of a lookup or an unset UI property.","commonSituations":"A UI label bound to a data field that is null until data arrives; concatenation helper returning null on error; deserialized Text property defaulted to null; localization key lookup returning null instead of empty string.","solutions":["Pass string.Empty instead of null when there is nothing to render","Guard: if (text != null) spriteBatch.DrawString(font, text, ...)","Coalesce at the call site: text ?? string.Empty","Fix the data source so the bound property is initialized to an empty string"],"exampleFix":"// before\nspriteBatch.DrawString(font, player.Name, pos); // Name may be null\n// after\nspriteBatch.DrawString(font, player.Name ?? string.Empty, pos);","handlingStrategy":"validation","validationCode":"if (text == null) text = string.Empty;\nspriteBatch.DrawString(font, text, position);","typeGuard":"static string SafeText(string s) => s ?? string.Empty;","tryCatchPattern":"try { spriteBatch.DrawString(font, text, pos); }\ncatch (ArgumentNullException) { spriteBatch.DrawString(font, string.Empty, pos); }","preventionTips":["Initialize text properties to string.Empty, not null","Never let localization lookups return null — fall back to key or empty string","Use ?? string.Empty at every DrawString/MeasureString call site"],"tags":["csharp","null-argument","graphics","text-rendering"],"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"}