stride3d/stride · error · InvalidOperationException

Expecting less than textures in input

Error message

Expecting less than {0} textures in input

What it means

UpdateParameters binds the effect's input textures to shader parameter slots and throws InvalidOperationException when there are more input textures than TexturingKeys.DefaultTextures.Count supports. The message is a literal template string that was never formatted via string.Format (ToFormat is applied), reporting the maximum texture count.

Solutions

  1. Reduce the number of SetInput calls to at most TexturingKeys.DefaultTextures.Count
  2. Extend the TexturingKeys.DefaultTextures array to support more slots
  3. Pack multiple textures into an atlas/texture array instead of separate slots

Example fix

// before
for (int i = 0; i < 8; i++) effect.SetInput(i, inputs[i]); // only 4 slots
// after
for (int i = 0; i < Math.Min(inputs.Count, TexturingKeys.DefaultTextures.Count); i++)
    effect.SetInput(i, inputs[i]);
Defensive patterns

Strategy: validation

Validate before calling

if (inputCount > TexturingKeys.DefaultTextures.Count) throw new InvalidOperationException($"Max {TexturingKeys.DefaultTextures.Count} inputs supported");

Try / catch

try { effect.Draw(context); } catch (InvalidOperationException ex) when (ex.Message.Contains("Expecting less than")) { /* reduce inputs or extend key set */ }

Prevention

When it happens

Trigger: Calling effect.SetInput(...) with more textures than TexturingKeys.DefaultTextures.Count (bounded loop capacity) and then drawing — PreDrawCore -> UpdateParameters hits the else branch for index i beyond the key array length.

Common situations: Feeding a large texture array (e.g. many shadow maps / layered inputs) into an image effect sized for fewer inputs; upgrading code where the default textures key set shrank; reusing a generic effect class with too many inputs.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/Images/ImageEffectShader.cs:136

        /// <remarks>By default, all the input textures will be remapped to <see cref="TexturingKeys.Texture0" />...etc.</remarks>
        protected virtual void UpdateParameters()
        {
            // By default, we are copying all input textures to TexturingKeys.Texture#
            var count = InputCount;
            for (int i = 0; i < count; i++)
            {
                var texture = GetInput(i);
                if (i < TexturingKeys.DefaultTextures.Count)
                {
                    var texturingKeys = texture != null && texture.ViewDimension == TextureDimension.TextureCube ? TexturingKeys.TextureCubes : TexturingKeys.DefaultTextures;
                    var texelSize = texture != null ? new Vector2(1.0f / texture.ViewWidth, 1.0f / texture.ViewHeight) : default;
                    // TODO GRAPHICS REFACTOR Do not use slow version
                    Parameters.Set(texturingKeys[i], texture);
                    Parameters.Set(TexturingKeys.TexturesTexelSize[i], texelSize);
                }
                else
                {
                    throw new InvalidOperationException("Expecting less than {0} textures in input".ToFormat(TexturingKeys.DefaultTextures.Count));
                }
            }
        }

        protected override unsafe void DrawCore(RenderDrawContext context)
        {
            // Clear render targets if there is a dependency conflict (D3D11 warning)
            if (delaySetRenderTargets)
                context.CommandList.ResetTargets();

            if (EffectInstance.UpdateEffect(GraphicsDevice) || pipelineStateDirty || previousBytecode != EffectInstance.Effect.Bytecode)
            {
                // The EffectInstance might have been updated from outside
                previousBytecode = EffectInstance.Effect.Bytecode;

                pipelineState.State.RootSignature = EffectInstance.RootSignature;
                pipelineState.State.EffectBytecode = EffectInstance.Effect.Bytecode;
                pipelineState.State.BlendState = blendState;

View on GitHub (pinned to 96fad776d2)