{"record":{"id":"cc04475839654d15","repo":"stride3d/stride","slug":"spritefont","errorCode":null,"errorMessage":"spriteFont","messagePattern":"spriteFont","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/SpriteBatch.cs","lineNumber":318,"sourceCode":"        /// <param name=\"layerDepth\">The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>\n        public void Draw(Texture texture, Vector2 position, RectangleF? sourceRectangle, Color4 color, float rotation, \n            Vector2 origin, Vector2 scale, SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0, Color4 colorAdd = default(Color4))\n        {\n            var destination = new RectangleF(position.X, position.Y, scale.X, scale.Y);\n            DrawSprite(texture, ref destination, true, ref sourceRectangle, color, colorAdd, rotation, ref origin, effects, orientation, layerDepth);\n        }\n\n        /// <summary>\n        /// Measure the size of the given text in virtual pixels depending on the target size.\n        /// </summary>\n        /// <param name=\"spriteFont\">The font used to draw the text.</param>\n        /// <param name=\"text\">The text to measure.</param>\n        /// <param name=\"targetSize\">The size of the target to render in. If null, the size of the window back buffer is used.</param>\n        /// <returns>The size of the text in virtual pixels.</returns>\n        /// <exception cref=\"ArgumentNullException\">The provided sprite font is null.</exception>\n        public Vector2 MeasureString(SpriteFont spriteFont, string text, Vector2? targetSize = null)\n        {\n            if (spriteFont == null) throw new ArgumentNullException(\"spriteFont\");\n\n            return MeasureString(spriteFont, text, spriteFont.Size, targetSize);\n        }\n\n        /// <summary>\n        /// Measure the size of the given text in virtual pixels depending on the target size.\n        /// </summary>\n        /// <param name=\"spriteFont\">The font used to draw the text.</param>\n        /// <param name=\"text\">The text to measure.</param>\n        /// <param name=\"fontSize\">The font size (in pixels) used to draw the text.</param>\n        /// <param name=\"targetSize\">The size of the target to render in. If null, the size of the window back buffer is used.</param>\n        /// <returns>The size of the text in virtual pixels.</returns>\n        /// <exception cref=\"ArgumentNullException\">The provided sprite font is null.</exception>\n        public Vector2 MeasureString(SpriteFont spriteFont, string text, float fontSize, Vector2? targetSize = null)\n        {\n            if (spriteFont == null) throw new ArgumentNullException(\"spriteFont\");\n\n            if (string.IsNullOrEmpty(text))","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/SpriteBatch.cs#L300-L336","documentation":"SpriteBatch.MeasureString(SpriteFont, string, Vector2?) measures text size using the given SpriteFont. A null spriteFont throws ArgumentNullException because font metrics are required to compute the layout.","triggerScenarios":"Calling MeasureString(null, text) — e.g. a font asset that failed to load or a null font field passed through from UI code.","commonSituations":"SpriteFont asset not present in build output, failed content loading, or unassigned font references in game/UI configuration.","solutions":["Ensure the SpriteFont is loaded before measuring text","Guard the call with a null check or default font","Fix font asset references/build inclusion"],"exampleFix":"// before\nvar size = spriteBatch.MeasureString(font, text);\n// after\nvar size = font != null ? spriteBatch.MeasureString(font, text) : Vector2.Zero;","handlingStrategy":"type-guard","validationCode":"if (spriteFont == null) return Vector2.Zero;","typeGuard":"bool HasFont(SpriteFont f) => f != null;","tryCatchPattern":"try { size = batch.MeasureString(font, text); } catch (ArgumentNullException) { size = Vector2.Zero; }","preventionTips":["Load SpriteFont assets before UI layout passes","Use a default/fallback font when the primary fails to load"],"tags":["graphics","text","null-argument"],"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"}