{"record":{"id":"379e642f55f32f22","repo":"stride3d/stride","slug":"tried-to-access-attribute-index","errorCode":null,"errorMessage":"Tried to access attribute index ","messagePattern":"Tried to access attribute index ","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Voxels/Voxels/Light/LightVoxelRenderer.cs","lineNumber":130,"sourceCode":"                ProcessedVoxelVolume processedVolume = voxelVolumeProcessor.GetProcessedVolumeForComponent(lightVoxel.Volume);\n                return processedVolume;\n            }\n\n            VoxelAttribute GetTraceAttr()\n            {\n                var lightVoxel = ((LightVoxel)Light.Type);\n\n                ProcessedVoxelVolume processedVolume = GetProcessedVolume();\n                if (processedVolume == null)\n                    return null;\n\n                if (processedVolume.OutputAttributes.Count > lightVoxel.AttributeIndex)\n                {\n                    return processedVolume.OutputAttributes[lightVoxel.AttributeIndex];\n                }\n                else\n                {\n                    throw new ArgumentOutOfRangeException(\"Tried to access attribute index \" + lightVoxel.AttributeIndex.ToString() + \" (zero-indexed) when the Voxel Volume Component has only \" + processedVolume.OutputAttributes.Count.ToString() + \" attributes.\");\n                }\n            }\n            public override void UpdateLayout(string compositionName)\n            {\n                base.UpdateLayout(compositionName);\n\n                traceAttribute = GetTraceAttr();\n\n                intensityKey = LightVoxelShaderKeys.Intensity.ComposeWith(compositionName);\n                specularIntensityKey = LightVoxelShaderKeys.SpecularIntensity.ComposeWith(compositionName);\n\n                diffuseMarcherKey = LightVoxelShaderKeys.diffuseMarcher.ComposeWith(compositionName);\n                specularMarcherKey = LightVoxelShaderKeys.specularMarcher.ComposeWith(compositionName);\n                attributeSamplersKey = MarchAttributesKeys.AttributeSamplers.ComposeWith(compositionName);\n\n                if (traceAttribute != null)\n                {\n                    if (((LightVoxel)Light.Type).DiffuseMarcher != null)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Voxels/Voxels/Light/LightVoxelRenderer.cs#L112-L148","documentation":"LightVoxelRenderer's GetTraceAttr throws ArgumentOutOfRangeException when the light's AttributeIndex is >= the number of entries in processedVolume.OutputAttributes. The index is zero-based and must select one of the voxel volume's output attributes for the light's trace. Typically this means the volume produces fewer attributes than the light expects.","triggerScenarios":"Setting LightVoxel.AttributeIndex to a value equal to or larger than the voxel volume's OutputAttributes.Count, often after changing the volume's attribute configuration.","commonSituations":"Changing a voxel volume's baked attributes so a previously chosen index no longer exists; copying a light from another scene with a different volume; setting index 1 on a volume that only outputs one attribute.","solutions":["Set AttributeIndex to a valid zero-based index within the volume's output attribute count.","Re-select the correct attribute in the light component after changing the voxel volume's configuration.","Before querying, check AttributeIndex < processedVolume.OutputAttributes.Count and clamp or fall back."],"exampleFix":"// before\nvar light = new LightVoxel { Volume = volume, AttributeIndex = 3 }; // volume has 2 attributes\n// after\nvar count = volume.OutputAttributes.Count; // ensure <= count-1\nvar light = new LightVoxel { Volume = volume, AttributeIndex = Math.Min(3, count - 1) };","handlingStrategy":"validation","validationCode":"if (lightVoxel.AttributeIndex >= processedVolume.OutputAttributes.Count)\n{\n    lightVoxel.AttributeIndex = 0; // clamp to a valid zero-based index\n}","typeGuard":"bool HasValidAttributeIndex(LightVoxel lv, ProcessedVoxelVolume vol) =>\n    lv.AttributeIndex >= 0 && lv.AttributeIndex < vol.OutputAttributes.Count;","tryCatchPattern":"try { attr = GetTraceAttr(); }\ncatch (ArgumentOutOfRangeException) { attr = processedVolume.OutputAttributes.FirstOrDefault(); }","preventionTips":["Re-check AttributeIndex whenever a voxel volume's attribute set changes.","Clamp indices to OutputAttributes.Count - 1 instead of hardcoding.","Prefer selecting attributes by name/lookup rather than raw index."],"tags":["stride","voxels","light","index-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}