stride3d/stride · error · ArgumentNullException

texture

Error message

texture

What it means

Argument-null validation in Sprite3DBatch.Draw: the texture parameter is null. Drawing a 3D sprite requires a texture to sample; the batch cannot enqueue a sprite without one, so it throws ArgumentNullException named 'texture'. Declared in the docs of the Draw overload that draws 3D sprites with element size, sorting mode, etc.

Solutions

  1. Ensure the texture is loaded before drawing (await asset load; check load errors)
  2. Guard the call: skip drawing when texture is null
  3. Fix the asset reference so the texture is included in the build output

Example fix

// before
batch.Draw(mySprite3D.Texture, ref world, ref src, ref size, ref color);
// after
if (mySprite3D.Texture != null)
    batch.Draw(mySprite3D.Texture, ref world, ref src, ref size, ref color);
Defensive patterns

Strategy: type-guard

Validate before calling

if (texture == null) return;

Type guard

bool IsDrawable(Texture t) => t != null && !t.IsDisposed;

Try / catch

try { batch.Draw(texture, ...); } catch (ArgumentNullException) { /* texture missing */ }

Prevention

When it happens

Trigger: Calling Draw(texture, ...) with texture == null — e.g. a Sprite3D component whose texture/material image failed to load or was not assigned.

Common situations: Missing or failed asset loads (texture asset absent from the build), unassigned fields in scene setup, or code paths where the texture is conditionally created but a null slips through.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/ea3be87186ef61e6. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/Sprite3DBatch.cs:71

        }

        /// <summary>
        /// Draw a 3D sprite (or add it to the draw list depending on the sortMode).
        /// </summary>
        /// <param name="texture">The texture to use during the draw</param>
        /// <param name="worldMatrix">The world matrix of the element</param>
        /// <param name="sourceRectangle">The rectangle indicating the source region of the texture to use</param>
        /// <param name="elementSize">The size of the sprite in the object space</param>
        /// <param name="color">The color to apply to the texture image.</param>
        /// <param name="imageOrientation">The rotation to apply on the image uv</param>
        /// <param name="swizzle">Swizzle mode indicating the swizzle use when sampling the texture in the shader</param>
        /// <param name="depth">The depth of the element. If null, it is calculated using world and view-projection matrix.</param>
        public void Draw(Texture texture, ref Matrix worldMatrix, ref RectangleF sourceRectangle, ref Vector2 elementSize, ref Color4 color,
                         ImageOrientation imageOrientation = ImageOrientation.AsIs, SwizzleMode swizzle = SwizzleMode.None, float? depth = null)
        {
            // Check that texture is not null
            if (texture == null)
                throw new ArgumentNullException("texture");

            // Skip items with null size
            if (elementSize.LengthSquared() < MathUtil.ZeroTolerance)
                return;

            // Calculate the information needed to draw.
            var drawInfo = new Sprite3DDrawInfo
            {
                Source =
                {
                    X = sourceRectangle.X / texture.ViewWidth,
                    Y = sourceRectangle.Y / texture.ViewHeight,
                    Width = sourceRectangle.Width / texture.ViewWidth,
                    Height = sourceRectangle.Height / texture.ViewHeight,
                },
                ColorScale = color,
                ColorAdd = new Color4(0, 0, 0, 0),
                Swizzle = swizzle,

View on GitHub (pinned to 96fad776d2)