{"record":{"id":"730c3c2f092070c1","repo":"Unity-Technologies/UnityCsReference","slug":"index-must-be-between-0-and-albedotextureproperti","errorCode":null,"errorMessage":"index must be between 0 and {albedoTexturePropertiesCount - 1}, but was {index}","messagePattern":"index must be between 0 and (.+?), but was (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GI/LightBaker.bindings.cs","lineNumber":591,"sourceCode":"        extern void Internal_SetAlbedoTextureData(uint index, TextureData textureData);\n\n        public TextureData GetAlbedoTextureData(uint index)\n        {\n            if (index >= albedoTextureCount)\n                throw new ArgumentException($\"index must be between 0 and {albedoTextureCount - 1}, but was {index}\");\n            return Internal_GetAlbedoTextureData(index);\n        }\n        public void SetAlbedoTextureData(uint index, TextureData textureData)\n        {\n            if (index >= albedoTextureCount)\n                throw new ArgumentException($\"index must be between 0 and {albedoTextureCount - 1}, but was {index}\");\n            Internal_SetAlbedoTextureData(index, textureData);\n        }\n        extern TextureProperties Internal_GetAlbedoTextureProperties(uint index);\n        public TextureProperties GetAlbedoTextureProperties(uint index)\n        {\n            if (index >= albedoTexturePropertiesCount)\n                throw new ArgumentException($\"index must be between 0 and {albedoTexturePropertiesCount - 1}, but was {index}\");\n            return Internal_GetAlbedoTextureProperties(index);\n        }\n        extern void Internal_SetAlbedoTextureProperties(uint index, TextureProperties textureProperties);\n        public void SetAlbedoTextureProperties(uint index, TextureProperties textureProperties)\n        {\n            if (index >= albedoTexturePropertiesCount)\n                throw new ArgumentException($\"index must be between 0 and {albedoTexturePropertiesCount - 1}, but was {index}\");\n            Internal_SetAlbedoTextureProperties(index, textureProperties);\n        }\n\n        public extern uint emissiveTextureCount { get; }\n        public extern uint emissiveTexturePropertiesCount { get; }\n        public extern uint transmissiveTextureCount { get; }\n        public extern uint transmissiveTexturePropertiesCount { get; }\n        extern TextureData Internal_GetEmissiveTextureData(uint index);\n        extern void Internal_SetEmissiveTextureData(uint index, TextureData textureData);\n        public TextureData GetEmissiveTextureData(uint index)\n        {","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GI/LightBaker.bindings.cs#L573-L609","documentation":"Thrown by BakeInput.GetAlbedoTextureProperties (the LightBaker bake-input object) when the supplied uint index is >= albedoTexturePropertiesCount. The properties collection is distinct from the albedo TextureData slots (albedoTextureCount): an index that is valid for data may be out of range for properties, so the count used to bound the loop must match the API being called.","triggerScenarios":"Calling bakeInput.GetAlbedoTextureProperties(i) inside a loop bounded by albedoTextureCount, instanceCount, or a scene mesh count while albedoTexturePropertiesCount is smaller; reading properties after InputExtraction populated TextureData but not TextureProperties.","commonSituations":"Custom bake readback pipelines that iterate albedo data and properties in lockstep assuming the two arrays are 1:1; off-by-one from using <= instead of <; reading properties on a BakeInput whose albedo properties were never populated.","solutions":["Bound the loop with the matching count: for (uint i = 0; i < bakeInput.albedoTexturePropertiesCount; i++) ...","If data and properties must be 1:1, align/grow them during InputExtraction before calling Get.","Guard the call site: if (index < bakeInput.albedoTexturePropertiesCount) { ... }"],"exampleFix":"// before\nfor (uint i = 0; i < bakeInput.albedoTextureCount; i++)\n    props.Add(bakeInput.GetAlbedoTextureProperties(i));\n// after\nfor (uint i = 0; i < bakeInput.albedoTexturePropertiesCount; i++)\n    props.Add(bakeInput.GetAlbedoTextureProperties(i));","handlingStrategy":"validation","validationCode":"if (index < bakeInput.albedoTexturePropertiesCount)\n{\n    var p = bakeInput.GetAlbedoTextureProperties(index);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the bound from the matching *Count property of the same prefix (properties vs data).","Keep albedo data and properties arrays aligned during InputExtraction.","Treat ArgumentException here as a caller bug, not a runtime hazard."],"tags":["lightmapping","gi","bake-input","index-bounds","albedo","properties","unity"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}