stride3d/stride · error · ArgumentOutOfRangeException

levelCoCValues and levelDownscaleFactors must be arrays of…

Error message

levelCoCValues and levelDownscaleFactors must be arrays of the same size!

What it means

DepthOfField.SetupTechnique requires that levelCoCValues and levelDownscaleFactors have identical lengths, since each blur level pairs a CoC value with a downscale factor. Mismatched array sizes throw ArgumentOutOfRangeException.

Solutions

  1. Make both arrays the same length with matching indices
  2. Regenerate both arrays together from a single level definition
  3. Clear one array if you only intend to customize the other (single-array mode is allowed)

Example fix

// before
dof.LevelCoCValues = new[] { 0.5f, 0.75f, 1.0f };
dof.LevelDownscaleFactors = new[] { 1, 2 };
// after
dof.LevelCoCValues = new[] { 0.5f, 0.75f, 1.0f };
dof.LevelDownscaleFactors = new[] { 1, 2, 4 };
Defensive patterns

Strategy: validation

Validate before calling

if (coc != null && dsf != null && coc.Length != dsf.Length) throw new ArgumentException("CoC and downscale arrays must match in length");

Type guard

bool LevelsMatch(float[] coc, int[] dsf) => coc == null || dsf == null || coc.Length == dsf.Length;

Try / catch

try { dof.SetupTechnique(); } catch (ArgumentOutOfRangeException) { /* log array length mismatch and fall back to defaults */ dof.LevelCoCValues = null; dof.LevelDownscaleFactors = null; dof.SetupTechnique(); }

Prevention

When it happens

Trigger: Setting levelCoCValues and levelDownscaleFactors to arrays of different lengths, then calling SetupTechnique or rendering (DrawCore).

Common situations: Adding a blur level to one array but not the other during tuning; loading mismatched arrays from config; off-by-one when building arrays programmatically.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/Images/DepthOfField/DepthOfField.cs:290

        }

        /// <summary>
        /// Caches the current configuration and re-generates the filter effect of each LOD level to avoid 
        /// generating garbage a each frame.
        /// </summary>
        public void SetupTechnique()
        {
            // Sanity checks
            if (levelCoCValues == null && levelDownscaleFactors != null)
            {
                throw new ArgumentOutOfRangeException("You cannot provide downscale factors without CoC values first.");
            }

            if (levelCoCValues != null && levelDownscaleFactors != null)
            {
                if (levelCoCValues.Length != levelDownscaleFactors.Length)
                {
                    throw new ArgumentOutOfRangeException("levelCoCValues and levelDownscaleFactors must be arrays of the same size!");
                }
            }

            if (levelCoCValues != null && levelCoCValues.Length == 0)
            {
                if (levelCoCValues.Length == 0)
                {
                    throw new ArgumentOutOfRangeException("DoF configuration needs at least one blur level!");
                }
                if (levelCoCValues[levelCoCValues.Length - 1] != 1f)
                {
                    throw new ArgumentOutOfRangeException("Last blurriest level must have a CoC of 1.0!");
                }
            }

            // Default values: 1 original image and 1 blur level
            int levelCount = 2;
            if (levelCoCValues != null)

View on GitHub (pinned to 96fad776d2)