stride3d/stride · error · ArgumentException
The provided value should be a power of 2
Error message
The provided value should be a power of 2
What it means
RadiancePrefilteringGGXNoCompute.SamplingsCount setter throws ArgumentException when the value is not a power of 2 (MathUtil.IsPow2 check). The prefilter shader's sampling pattern assumes power-of-2 sample counts, so values like 100 or 500 are rejected even when within the 1024 cap.
Solutions
- Round to the nearest power of 2 before assigning.
- Use canonical values: 16, 32, 64, 128, 256, 512, 1024.
- Validate/normalize the config value at load time so bad values never hit the setter.
Example fix
// before prefilter.SamplingsCount = 1000; // after prefilter.SamplingsCount = 512; // power of 2, <= 1024
Defensive patterns
Strategy: validation
Validate before calling
int normalized = Math.Clamp(value, 1, 1024); if ((normalized & (normalized - 1)) != 0) normalized = MathUtil.NextPowerOfTwo(normalized); prefilter.SamplingsCount = normalized;
Type guard
bool IsValidSamplingsCount(int v) => v >= 1 && v <= 1024 && (v & (v - 1)) == 0;
Try / catch
try { prefilter.SamplingsCount = value; }
catch (ArgumentException ex) { Log.Warning("SamplingsCount must be a power of 2"); prefilter.SamplingsCount = MathUtil.NextPowerOfTwo(Math.Min(value, 1024)); } Prevention
- Normalize sample counts (pow2, <=1024) at the config/UI boundary.
- Share one validation helper across RadiancePrefilteringGGX and NoCompute variants.
- Add tests covering 0, negative, non-pow2 and >1024 inputs.
When it happens
Trigger: Assigning a non-power-of-2 SamplingsCount (e.g. 100, 300, 1000) to RadiancePrefilteringGGXNoCompute.
Common situations: Sample counts coming from UI sliders or config files with arbitrary values; computing counts from image width/height arithmetic; porting quality settings from tools that allowed arbitrary sample counts.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- The provided value should be a power of 2
- value
- value
- Only array of 2D textures are currently supported as output
- Only cubemaps are currently supported as input
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/e2abbc6ffa5335ba.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Rendering/Rendering/ComputeEffect/GGXPrefiltering/RadiancePrefilteringGGXNoCompute.cs:69
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;
if (input == null || input.ViewDimension != TextureDimension.TextureCube)
throw new NotSupportedException("Only cubemaps are currently supported as input");
View on GitHub (pinned to 96fad776d2)