stride3d/stride · error · ArgumentOutOfRangeException
Radius cannot be < 0
Error message
Radius cannot be < 0
What it means
The Radius property setter of BokehBlur (depth-of-field bokeh technique) throws ArgumentOutOfRangeException when a negative value is assigned. Values below 1 are silently clamped to 1 texel because at least one texel radius is required to perform a blur, but negative values are rejected outright.
Solutions
- Clamp the radius with Math.Max(0f, radius) before assigning.
- Validate user-facing input so the radius can never go negative.
- Note values in [0,1) are auto-clamped to 1 by the setter, so only negatives need guarding.
Example fix
// before bokeh.Radius = computedRadius; // can be negative // after bokeh.Radius = MathF.Max(0f, computedRadius);
Defensive patterns
Strategy: validation
Validate before calling
float safeRadius = Math.Clamp(radius, 0f, float.MaxValue); bokeh.Radius = safeRadius;
Type guard
bool IsValidRadius(float r) => !float.IsNaN(r) && !float.IsInfinity(r) && r >= 0f;
Try / catch
try { bokeh.Radius = r; }
catch (ArgumentOutOfRangeException ex) { bokeh.Radius = 1f; Log.Warn(ex, "Radius clamped"); } Prevention
- Clamp computed radii to non-negative values
- Constrain UI sliders to 0..max range
- Validate config-file radius values at load time
When it happens
Trigger: Assigning bokehBlur.Radius = -1 (or any negative float), usually from a computed value such as a scaled focus parameter or user input that wasn't clamped.
Common situations: Camera focus/blur configuration driven by UI sliders allowing negatives; computations like radius = someScale * factor that can yield negative results; config files with negative radius entries.
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
- A negative number of mip maps is not allowed.
- ArgumentOutOfRangeException
- ArgumentOutOfRangeException
- ArgumentOutOfRangeException
- Asked for " + i + " but no more than 10 default textures…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/7a28766f47a47724.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Rendering/Rendering/Images/DepthOfField/BokehTechnique/BokehBlur.cs:59
/// <summary>
/// Sets the radius of the blur.
/// A child class can override it to do special processing when a new value is provided.
/// </summary>
/// <param name="value">The new value of the blur.</param>
[DataMemberIgnore]
public virtual float Radius
{
get
{
return radius;
}
set
{
if (value < 0f)
{
throw new ArgumentOutOfRangeException("Radius cannot be < 0");
}
if (value < 1f)
{
// We need at least a radius of 1 texel to perform a blur.
value = 1f;
}
this.radius = value;
}
}
}
}
View on GitHub (pinned to 96fad776d2)