stride3d/stride · error · ArgumentOutOfRangeException

slot must be in the range [0, 15]

Error message

slot must be in the range [0, 15]

What it means

A validation guard in ImageEffect.SetInput: the slot parameter is outside the supported range [0, 15]. Input textures are stored in a fixed-size array of 16 slots; indexing beyond it would throw a raw out-of-range error or corrupt state, so the method validates the slot and throws with the message 'slot must be in the range [0, 15]'.

Solutions

  1. Use a slot index between 0 and 15
  2. Check inputTextures.Length / the effect's actual max inputs before assigning
  3. Add a bounds check or clamping around the SetInput call

Example fix

// before
for (int i = 0; i < inputs.Count; i++)
    effect.SetInput(i, inputs[i]);
// after
for (int i = 0; i < Math.Min(inputs.Count, 16); i++)
    effect.SetInput(i, inputs[i]);
Defensive patterns

Strategy: validation

Validate before calling

if (slot < 0 || slot > 15) throw new ArgumentException("slot must be in [0, 15]"); effect.SetInput(slot, texture);

Type guard

bool IsValidInputSlot(int slot) => slot >= 0 && slot < 16;

Try / catch

try { effect.SetInput(slot, texture); } catch (ArgumentOutOfRangeException) { /* clamp or log: invalid slot */ }

Prevention

When it happens

Trigger: Calling SetInput with a negative slot or a slot >= 16, e.g. building inputs in a loop without a bound, or a hardcoded slot from a mismatched effect definition.

Common situations: Loops that iterate over a list longer than the effect's max inputs; copy-pasted slot indices from another effect; generic image-effect composition code assuming more inputs than supported.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/Images/ImageEffect.cs:80

        {
            Initialize(context);
        }

        /// <summary>
        /// Gets or sets a boolean to enable GraphicsDevice.SetDepthAndRenderTargets from output. Default is <c>true</c>.
        /// </summary>
        /// <value>A boolean to enable GraphicsDevice.SetDepthAndRenderTargets from output. Default is <c>true</c></value>
        protected bool EnableSetRenderTargets { get; set; }

        /// <summary>
        /// Sets an input texture
        /// </summary>
        /// <param name="slot">The slot.</param>
        /// <param name="texture">The texture.</param>
        public void SetInput(int slot, Texture texture)
        {
            if (slot < 0 || slot >= inputTextures.Length)
                throw new ArgumentOutOfRangeException(nameof(slot), "slot must be in the range [0, 15]");

            inputTextures[slot] = texture;
            if (slot > maxInputTextureIndex)
            {
                maxInputTextureIndex = slot;
            }
        }

        /// <summary>
        /// Resets the state of this effect.
        /// </summary>
        public override void Reset()
        {
            base.Reset();

            maxInputTextureIndex = -1;
            Array.Clear(inputTextures, 0, inputTextures.Length);
            outputDepthStencilView = null;

View on GitHub (pinned to 96fad776d2)