stride3d/stride · error · ArgumentOutOfRangeException

value

Error message

value

What it means

RadiancePrefilteringGGXNoCompute.SamplingsCount setter throws ArgumentOutOfRangeException when the value exceeds 1024. Like the compute variant, the non-compute prefiltering effect supports at most 1024 importance samples per prefiltered mip and rejects larger values to protect the shader's sample loop.

Solutions

  1. Set SamplingsCount to a value <= 1024.
  2. Pick a power-of-2 value such as 256 or 512 for quality/perf balance.
  3. Clamp at load time: Math.Min(value, 1024) before assignment.

Example fix

// before
prefilter.SamplingsCount = 4096;
// after
prefilter.SamplingsCount = 1024; // max supported
Defensive patterns

Strategy: validation

Validate before calling

if (samplings > 1024)
    throw new ArgumentOutOfRangeException(nameof(samplings), "Max SamplingsCount is 1024");
prefilter.SamplingsCount = samplings;

Type guard

bool IsValidSamplingsCount(int v) => v <= 1024 && v >= 1 && (v & (v - 1)) == 0;

Try / catch

try { prefilter.SamplingsCount = value; }
catch (ArgumentOutOfRangeException ex) { Log.Warning("SamplingsCount capped at 1024"); prefilter.SamplingsCount = 1024; }

Prevention

When it happens

Trigger: Assigning RadiancePrefilteringGGXNoCompute.SamplingsCount a value > 1024 (e.g. 2048) before rendering.

Common situations: Raising sample counts for higher-quality IBL beyond the supported cap; deserializing user settings with unvalidated sample counts; assuming the same limits as other engines' prefilter tools.

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


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

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/ComputeEffect/GGXPrefiltering/RadiancePrefilteringGGXNoCompute.cs:66

            : base(context, "RadiancePrefilteringGGX")
        {
            shader = new ImageEffectShader("RadiancePrefilteringGGXNoComputeEffect");
            resampleShader = new ImageEffectShader("CubemapFaceResampleShader");
            DoNotFilterHighestLevel = true;
            samplingsCount = 1024;
        }

        /// <summary>
        /// Gets or sets the number of sampling used during the importance sampling
        /// </summary>
        /// <remarks>Should be a power of 2 and maximum value is 1024</remarks>
        public int SamplingsCount
        {
            get { return samplingsCount; }
            set
            {
                if (value > 1024)
                    throw new ArgumentOutOfRangeException(nameof(value));

                if (!MathUtil.IsPow2(value))
                    throw new ArgumentException("The provided value should be a power of 2");

                samplingsCount = Math.Max(1, value);
            }
        }

        protected override void DrawCore(RenderDrawContext context)
        {
            var output = PrefilteredRadiance;
            if (output == null || (output.ViewDimension != TextureDimension.Texture2D && output.ViewDimension != TextureDimension.TextureCube) || output.ArraySize != 6)
                throw new NotSupportedException("Only array of 2D textures are currently supported as output");

            if (!output.IsRenderTarget)
                throw new NotSupportedException("Only render targets are supported as output");

            var input = RadianceMap;

View on GitHub (pinned to 96fad776d2)