stride3d/stride · error · ArgumentOutOfRangeException

Radius cannot be < 0

Error message

Radius cannot be < 0

What it means

The Radius property of CoCMapBlur's blur weights setter rejects negative values with ArgumentOutOfRangeException. The radius controls the blur kernel size for the circle-of-confusion map and cannot be negative.

Solutions

  1. Clamp the value before assigning: Radius = Math.Max(0, value)
  2. Fix the calculation or configuration that produced a negative radius
  3. Use 0 radius if no blur is desired instead of a negative one

Example fix

// before
blur.Radius = (int)(coc * scale);
// after
blur.Radius = Math.Max(0, (int)(coc * scale));
Defensive patterns

Strategy: validation

Validate before calling

if (radius < 0) throw new ArgumentException("Radius must be >= 0"); blur.Radius = radius;

Type guard

bool IsValidRadius(int r) => r >= 0;

Try / catch

try { blur.Radius = value; } catch (ArgumentOutOfRangeException) { blur.Radius = 0; }

Prevention

When it happens

Trigger: Assigning any negative value to the Radius property of CoCMapBlur, e.g. blurEffect.Radius = -1, or computing a radius from a formula that can go below 0.

Common situations: Deriving radius from scene scale or resolution where a bad parameter makes it negative; typo in tuning values; data-driven configs with negative entries.

Related errors


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

Appendix: source

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

        {
            Radius = 5f;
        }

        /// <summary>
        /// Gets or sets the radius.
        /// </summary>
        /// <value>The radius.</value>
        public float Radius
        {
            get
            {
                return radius;
            }
            set
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException("Radius cannot be < 0");
                }

                weightsDirty = (radius != value);
                radius = value;
            }
        }

        protected override void InitializeCore()
        {
            base.InitializeCore();

            cocBlurEffect = ToLoadAndUnload(new ImageEffectShader("CoCMapBlurEffect"));
        }

        protected override void DrawCore(RenderDrawContext context)
        {
            // Updates the weight array if necessary
            if (weightsDirty || tapCount == 0)

View on GitHub (pinned to 96fad776d2)