stride3d/stride · error · ArgumentNullException

texture

Error message

texture

What it means

Thrown by UIBatch.DrawImage when the texture parameter is null. The public DrawImage overload validates its required texture before computing draw information. Raised as ArgumentNullException with param name "texture".

Solutions

  1. Ensure the texture is loaded and assigned before batching (await load, or use a placeholder texture).
  2. Null-check the texture at the call site and skip or substitute a white pixel texture.
  3. Verify the asset reference in the UI component is not null at draw time.

Example fix

// before
uiBatch.DrawImage(element.Texture, ref world, ref source, ref size, ref border, ref color, 0);
// after
if (element.Texture != null)
    uiBatch.DrawImage(element.Texture, ref world, ref source, ref size, ref border, ref color, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (texture == null) return; // or use placeholder
texture.Validate();

Type guard

bool HasTexture(UIElement e) => (e as UIImageElement)?.Texture != null;

Try / catch

try { uiBatch.DrawImage(texture, ...); }
catch (ArgumentNullException e) when (e.ParamName == "texture") { log.Warning("DrawImage skipped: null texture"); }

Prevention

When it happens

Trigger: Calling UIBatch.DrawImage(null, ...) — typically when a SpriteField/UI element's texture has not been assigned or a texture load failed and returned null.

Common situations: UI image whose Texture property is unset; asynchronous texture load not finished; asset not found leaving the reference null.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/UIBatch.cs:331

        }

        /// <summary>
        /// Batch a new border image draw to the draw list.
        /// </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 ui element</param>
        /// <param name="borderSize">The size of the borders in the texture in pixels (left/top/right/bottom)</param>
        /// <param name="color">The color to apply to the texture image.</param>
        /// <param name="depthBias">The depth bias of the ui element</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="snapImage">Indicate if the image needs to be snapped or not</param>
        public void DrawImage(Texture texture, ref Matrix worldMatrix, ref RectangleF sourceRectangle, ref Vector3 elementSize, ref Vector4 borderSize,
            ref Color color, int depthBias, ImageOrientation imageOrientation = ImageOrientation.AsIs, SwizzleMode swizzle = SwizzleMode.None, bool snapImage = false)
        {
            if (texture == null) throw new ArgumentNullException(nameof(texture));

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

            // Calculate the information needed to draw.
            var drawInfo = new UIImageDrawInfo
            {
                Source =
                {
                    X = sourceRectangle.X / texture.ViewWidth,
                    Y = sourceRectangle.Y / texture.ViewHeight,
                    Width = sourceRectangle.Width / texture.ViewWidth,
                    Height = sourceRectangle.Height / texture.ViewHeight,
                },
                DepthBias = depthBias,
                ColorScale = color,
                ColorAdd = Color.Zero,

View on GitHub (pinned to 96fad776d2)