{"record":{"id":"9820dd23ec5dd839","repo":"stride3d/stride","slug":"the-provided-value-should-be-a-power-of-2","errorCode":null,"errorMessage":"The provided value should be a power of 2","messagePattern":"The provided value should be a power of 2","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/ComputeEffect/GGXPrefiltering/RadiancePrefilteringGGX.cs","lineNumber":66,"sourceCode":"            computeShader = new ComputeEffectShader(context) { ShaderSourceName = \"RadiancePrefilteringGGXEffect\" };\n            DoNotFilterHighestLevel = true;\n            samplingsCount = 1024;\n        }\n\n        /// <summary>\n        /// Gets or sets the number of sampling used during the importance sampling\n        /// </summary>\n        /// <remarks>Should be a power of 2 and maximum value is 1024</remarks>\n        public int SamplingsCount\n        {\n            get { return samplingsCount; }\n            set\n            {\n                if (value > 1024)\n                    throw new ArgumentOutOfRangeException(\"value\");\n\n                if (!MathUtil.IsPow2(value))\n                    throw new ArgumentException(\"The provided value should be a power of 2\");\n\n                samplingsCount = Math.Max(1, value);\n            }\n        }\n\n        protected override void DrawCore(RenderDrawContext context)\n        {\n            var output = PrefilteredRadiance;\n            if (output == null || (output.ViewDimension != TextureDimension.Texture2D && output.ViewDimension != TextureDimension.TextureCube) || output.ArraySize != 6)\n                throw new NotSupportedException(\"Only array of 2D textures are currently supported as output\");\n\n            if (!output.IsUnorderedAccess || output.IsRenderTarget)\n                throw new NotSupportedException(\"Only non-rendertarget unordered access textures are supported as output\");\n\n            var input = RadianceMap;\n            if (input == null || input.Dimension != TextureDimension.TextureCube)\n                throw new NotSupportedException(\"Only cubemaps are currently supported as input\");\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/ComputeEffect/GGXPrefiltering/RadiancePrefilteringGGX.cs#L48-L84","documentation":"RadiancePrefilteringGGX.SamplingsCount setter throws ArgumentException when the value is not a power of 2 (checked with MathUtil.IsPow2). The prefiltering shader distributes samples in power-of-2 strides, so any non-power-of-2 sample count is rejected even if <= 1024.","triggerScenarios":"Assigning SamplingsCount = 100, 300, 500 or any value that fails MathUtil.IsPow2.","commonSituations":"Deriving sample count from UI sliders or user config with arbitrary values; computing counts from mip size arithmetic that doesn't yield a power of 2; porting settings from another IBL tool that allowed arbitrary counts.","solutions":["Round the value to the nearest power of 2 before assigning (e.g. MathUtil.NextPowerOfTwo).","Use canonical values: 1, 2, 4, 8, ..., 512, 1024.","Add a clamp/round helper at the config-loading boundary so invalid values never reach the setter."],"exampleFix":"// before\nprefilter.SamplingsCount = 300;\n// after\nprefilter.SamplingsCount = 256; // power of 2\n// or generic: int v = MathUtil.NextPowerOfTwo(300); prefilter.SamplingsCount = Math.Min(v, 1024);","handlingStrategy":"validation","validationCode":"int normalized = MathUtil.NextPowerOfTwo(Math.Max(1, Math.Min(value, 1024)));\nprefilter.SamplingsCount = normalized;","typeGuard":"bool IsPow2(int v) => v > 0 && (v & (v - 1)) == 0;","tryCatchPattern":"try { prefilter.SamplingsCount = value; }\ncatch (ArgumentException ex) { Log.Warning(\"SamplingsCount must be a power of 2; rounding up\"); prefilter.SamplingsCount = MathUtil.NextPowerOfTwo(value); }","preventionTips":["Round any externally sourced count to the nearest power of 2 before assignment.","Restrict UI sliders to discrete power-of-2 steps.","Unit-test config loading with non-pow2 inputs."],"tags":["rendering","pbr","prefiltering","validation","stride"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}