{"record":{"id":"4a7c099c4c1bb85a","repo":"stride3d/stride","slug":"texture-spritebatch","errorCode":null,"errorMessage":"texture","messagePattern":"texture","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/SpriteBatch.cs","lineNumber":520,"sourceCode":"            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);\n            drawCommand.Position.Y = MathF.Round(drawCommand.Position.Y);\n            drawCommand.Position.X /= resolutionRatio.X;\n            drawCommand.Position.Y /= resolutionRatio.Y;\n\n            spriteFont.InternalDraw(commandList, text, ref drawCommand, alignment);\n        }\n        \n        internal unsafe void DrawSprite(Texture texture, ref RectangleF destination, bool scaleDestination, ref RectangleF? sourceRectangle, Color4 color, Color4 colorAdd,\n            float rotation, ref Vector2 origin, SpriteEffects effects, ImageOrientation orientation, float depth, SwizzleMode swizzle = SwizzleMode.None, bool realSize = false)\n        {\n            // Check that texture is not null\n            if (texture == null)\n            {\n                throw new ArgumentNullException(\"texture\");\n            }\n            \n            // Put values in next ElementInfo\n            var elementInfo = new ElementInfo();\n            var spriteInfo = &elementInfo.DrawInfo;\n\n            float width;\n            float height;\n\n            // If the source rectangle has a value, then use it.\n            if (sourceRectangle.HasValue)\n            {\n                var rectangle = sourceRectangle.Value;\n                spriteInfo->Source.X = rectangle.X;\n                spriteInfo->Source.Y = rectangle.Y;\n                width = rectangle.Width;\n                height = rectangle.Height;\n            }","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/SpriteBatch.cs#L502-L538","documentation":"SpriteBatch.DrawSprite (invoked by the public SpriteBatch.Draw overloads) throws ArgumentNullException when the texture parameter is null. The batcher needs a valid GPU texture to record an element; null would corrupt the draw-command list. Note the public Draw overloads typically return silently for null textures — this direct path throws.","triggerScenarios":"Calling SpriteBatch.Draw / DrawSprite with a null Texture — e.g. a Texture field never assigned, a render target not yet allocated, or content load failure.","commonSituations":"Sprite component whose texture reference is broken after asset rename; drawing before the render target is created; platform texture load failing silently and returning null; scene referencing a texture removed from the asset folder.","solutions":["Ensure the texture is loaded/created before drawing; Content.Load the asset ahead of the draw call","Skip drawing when null: if (texture != null) spriteBatch.Draw(texture, ...)","Initialize textures in Start/Initialize instead of lazily in Draw","Verify the texture asset exists and its reference is not broken in the scene"],"exampleFix":"// before\nspriteBatch.Draw(texture, position, region, Color.White);\n// after\nif (texture != null)\n    spriteBatch.Draw(texture, position, region, Color.White);","handlingStrategy":"type-guard","validationCode":"if (texture == null || texture.IsDisposed) return; // skip this frame\nspriteBatch.Draw(texture, destination, sourceRectangle, Color.White);","typeGuard":"static bool IsDrawable(Texture t) => t != null && !t.IsDisposed;","tryCatchPattern":"try { spriteBatch.Draw(texture, rect, null, Color.White); }\ncatch (ArgumentNullException) { Log.Warning(\"Draw skipped: texture not loaded\"); }","preventionTips":["Assign textures during content initialization, before the first frame","Check texture asset references after renames in the asset pipeline","Guard all conditional draws with a null check on the texture field"],"tags":["csharp","null-argument","graphics","texture"],"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"}