{"record":{"id":"8b463344ac5a09d6","repo":"stride3d/stride","slug":"too-many-scattering-materials-present-in-order-to-be-able-to","errorCode":null,"errorMessage":"Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is 8.","messagePattern":"Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is 8\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/Images/SubsurfaceScattering/SubsurfaceScatteringBlur.cs","lineNumber":264,"sourceCode":"            blurVShader.SetInput(ColorInputIndex, inputFrameBufferColorAttachmentCopy); // Color attachment -> Texture0\n            blurVShader.SetOutput(outputFrameBuffer);\n\n            for (int i = 0; i < NumberOfPasses; ++i)\n            {\n                //blurHShader.Parameters.Set(SubsurfaceScatteringBlurShaderKeys.AngularOffset, (float)i / (float)NumberOfPasses * System.Math.PI);\n                SetValueParameterForBothShaders(SubsurfaceScatteringBlurShaderKeys.IterationNumber, (float)i);\n\n                // Perform the actual rendering:\n                blurHShader.Draw(context, \"SubsurfaceScattering_blur_H\");\n                blurVShader.Draw(context, \"SubsurfaceScattering_blur_V\");\n            }\n        }\n\n        public void SetScatteringWidth(uint materialIndex, float width)\n        {\n            if (materialIndex > MaxMaterialCount)\n            {\n                throw new Exception(\"Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is \" + MaxMaterialCount + \".\");\n            }\n\n            materialScatteringWidths[materialIndex] = width;\n        }\n\n        public void SetScatteringKernel(uint materialIndex, Vector4[] scatteringKernel)\n        {\n            if (materialIndex > MaxMaterialCount)\n            {\n                throw new Exception(\"Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is \" + MaxMaterialCount + \".\");\n            }\n\n            scatteringKernel.CopyTo(materialScatteringKernels, (int)materialIndex * SubsurfaceScatteringSettings.SamplesPerScatteringKernel2);   // Insert into the global scattering kernel array.\n        }\n\n        /// <summary>\n        /// If active, the the light won't scatter across large depth differences.\n        /// The depth falloff can be configured using \"Depth falloff strength\".","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/Images/SubsurfaceScattering/SubsurfaceScatteringBlur.cs#L246-L282","documentation":"SetScatteringWidth stores per-material scattering widths into a fixed-size array limited by MaxMaterialCount (8). Passing materialIndex > 8 would overflow the backing array, so the method throws a plain Exception with the 'Maximum count is 8' message. Note the check uses > rather than >= so index exactly 8 is also out of bounds at runtime.","triggerScenarios":"Calling SetScatteringWidth with materialIndex 9+ (or 8, which passes the check but overflows materialScatteringWidths), e.g. when a scene has more than 8 subsurface-scattering materials.","commonSituations":"Scenes with many SSS materials exceeding the shader's fixed constant buffer size; per-material loops that iterate past the MaxMaterialCount constant.","solutions":["Keep the number of scattering materials at or below 8 (indices 0-7)","Merge or drop excess SSS materials before registering them with SubsurfaceScatteringBlur","Use materialIndex values strictly less than MaxMaterialCount"],"exampleFix":"// before\nblur.SetScatteringWidth(9, width); // throws\n// after\nif (materialIndex < SubsurfaceScatteringBlur.MaxMaterialCount)\n    blur.SetScatteringWidth(materialIndex, width);","handlingStrategy":"validation","validationCode":"if (materialIndex >= SubsurfaceScatteringBlur.MaxMaterialCount)\n    throw new ArgumentException(\"materialIndex must be < MaxMaterialCount (8)\");","typeGuard":null,"tryCatchPattern":"try { blur.SetScatteringWidth(i, width); }\ncatch (Exception) { logger.Warning(\"Too many SSS materials; dropping index \" + i); }","preventionTips":["Cap SSS material collection at 8 before registration","Track the count in a central registry, not per-call","Remember index 8 also overflows: use strict <"],"tags":["csharp","rendering","index-out-of-range"],"backgroundTag":"index-out-of-bounds","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}