{"record":{"id":"e2abbc6ffa5335ba","repo":"stride3d/stride","slug":"the-provided-value-should-be-a-power-of-2-e2abbc","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/RadiancePrefilteringGGXNoCompute.cs","lineNumber":69,"sourceCode":"            resampleShader = new ImageEffectShader(\"CubemapFaceResampleShader\");\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(nameof(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.IsRenderTarget)\n                throw new NotSupportedException(\"Only render targets are supported as output\");\n\n            var input = RadianceMap;\n            if (input == null || input.ViewDimension != TextureDimension.TextureCube)\n                throw new NotSupportedException(\"Only cubemaps are currently supported as input\");\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/ComputeEffect/GGXPrefiltering/RadiancePrefilteringGGXNoCompute.cs#L51-L87","documentation":"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.","triggerScenarios":"Assigning a non-power-of-2 SamplingsCount (e.g. 100, 300, 1000) to RadiancePrefilteringGGXNoCompute.","commonSituations":"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.","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."],"exampleFix":"// before\nprefilter.SamplingsCount = 1000;\n// after\nprefilter.SamplingsCount = 512; // power of 2, <= 1024","handlingStrategy":"validation","validationCode":"int normalized = Math.Clamp(value, 1, 1024);\nif ((normalized & (normalized - 1)) != 0) normalized = MathUtil.NextPowerOfTwo(normalized);\nprefilter.SamplingsCount = normalized;","typeGuard":"bool IsValidSamplingsCount(int v) => v >= 1 && v <= 1024 && (v & (v - 1)) == 0;","tryCatchPattern":"try { prefilter.SamplingsCount = value; }\ncatch (ArgumentException ex) { Log.Warning(\"SamplingsCount must be a power of 2\"); prefilter.SamplingsCount = MathUtil.NextPowerOfTwo(Math.Min(value, 1024)); }","preventionTips":["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."],"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"}