stride3d/stride · error · ArgumentOutOfRangeException

Asked for " + i + " but no more than 10 default textures…

Error message

Asked for " + i + " but no more than 10 default textures are currently supported

What it means

MaterialUtility.GetDefaultSamplerKey maps a sampler index to the corresponding TexturingKeys.SamplerN name; the engine supports indices 0 through 9. A negative or >= 10 index hits the default case and throws ArgumentOutOfRangeException.

Solutions

  1. Clamp or reject sampler indices to 0..9 before calling GetDefaultSamplerKey
  2. Rework custom materials needing more samplers to use explicit sampler names instead of the defaults
  3. Keep the texture count of the material within the 10-default-sampler limit

Example fix

// before
var key = MaterialUtility.GetDefaultSamplerKey(textureIndex);
// after
if (textureIndex < 0 || textureIndex > 9)
    throw new ArgumentOutOfRangeException(nameof(textureIndex), "Only samplers 0..9 are supported");
var key = MaterialUtility.GetDefaultSamplerKey(textureIndex);
Defensive patterns

Strategy: validation

Validate before calling

if (index < 0 || index > 9) throw new ArgumentOutOfRangeException(nameof(index));
var samplerKey = MaterialUtility.GetDefaultSamplerKey(index);

Try / catch

try { key = MaterialUtility.GetDefaultSamplerKey(i); }
catch (ArgumentOutOfRangeException) { key = TexturingKeys.Sampler0; /* or fail fast */ }

Prevention

When it happens

Trigger: Calling MaterialUtility.GetDefaultSamplerKey with an index < 0 or > 9, typically from a custom material pass or shader generator that loops over more textures/samplers than the 10 default slots.

Common situations: Custom material generators iterating texture arrays larger than 10; off-by-one or negative index from a computed sampler slot.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/Materials/MaterialUtility.cs:136

                    return TexturingKeys.Sampler1;
                case 2:
                    return TexturingKeys.Sampler2;
                case 3:
                    return TexturingKeys.Sampler3;
                case 4:
                    return TexturingKeys.Sampler4;
                case 5:
                    return TexturingKeys.Sampler5;
                case 6:
                    return TexturingKeys.Sampler6;
                case 7:
                    return TexturingKeys.Sampler7;
                case 8:
                    return TexturingKeys.Sampler8;
                case 9:
                    return TexturingKeys.Sampler9;
                default:
                    throw new ArgumentOutOfRangeException("Asked for " + i + " but no more than 10 default textures are currently supported");
            }
        }

        /// <summary>
        /// Clamps <see cref="ComputeColors.ComputeFloat"/> value within a specified range [min; max].
        /// </summary>
        /// <param name="key">Input scalar.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        public static void ClampFloat([NotNull] this IComputeScalar key, float min, float max)
        {
            var asFloat = key as ComputeColors.ComputeFloat;
            if (asFloat != null)
                asFloat.Value = MathUtil.Clamp(asFloat.Value, min, max);
        }

        /// <summary>
        /// Clamps <see cref="ComputeColors.ComputeFloat4"/> value within a specified range [min; max].

View on GitHub (pinned to 96fad776d2)