{"record":{"id":"6e34490d6da93173","repo":"MonoGame/MonoGame","slug":"cubemapface","errorCode":null,"errorMessage":"cubeMapFace","messagePattern":"cubeMapFace","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Graphics/RenderTargetBinding.cs","lineNumber":75,"sourceCode":"            _depthFormat = renderTarget.DepthStencilFormat;\n\t\t}\n\n        /// <summary>\n        /// Creates a new <b>RenderTargetBinding</b> with the specified parameters.\n        /// </summary>\n        /// <param name=\"renderTarget\">A cube map render target.</param>\n        /// <param name=\"cubeMapFace\">The cube map of the render target.</param>\n        /// <exception cref=\"ArgumentNullException\">The <paramref name=\"renderTarget\"/> parameter is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// The <paramref name=\"cubeMapFace\"/> parameter is less than <see cref=\"CubeMapFace.PositiveX\"/> or greater\n        /// than <see cref=\"CubeMapFace.NegativeZ\"/>.\n        /// </exception>\n        public RenderTargetBinding(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)\n        {\n            if (renderTarget == null)\n                throw new ArgumentNullException(\"renderTarget\");\n            if (cubeMapFace < CubeMapFace.PositiveX || cubeMapFace > CubeMapFace.NegativeZ)\n                throw new ArgumentOutOfRangeException(\"cubeMapFace\");\n\n            _renderTarget = renderTarget;\n            _arraySlice = (int)cubeMapFace;\n            _depthFormat = renderTarget.DepthStencilFormat;\n        }\n\n#if DIRECTX\n\n        /// <summary>\n        /// Creates a new <b>RenderTargetBinding</b> with the specified parameters.\n        /// </summary>\n        /// <param name=\"renderTarget\">The render target to create the binding for.</param>\n        /// <param name=\"arraySlice\">The index of the texture array slice to bind.</param>\n        /// <exception cref=\"ArgumentNullException\">The <paramref name=\"renderTarget\" /> parameter is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// The <paramref name=\"arraySlice\" /> is less than zero or greater than the array size of the render target\n        /// </exception>\n        /// <exception cref=\"InvalidOperationException\">Texture arrays are not supported by the current graphics device.</exception>","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Graphics/RenderTargetBinding.cs#L57-L93","documentation":"Thrown by the RenderTargetBinding(RenderTargetCube, CubeMapFace) constructor when cubeMapFace is outside the valid CubeMapFace enum range (PositiveX..NegativeZ). The face index maps directly to an array slice, so an out-of-range value would index an invalid cube face.","triggerScenarios":"Casting an arbitrary integer to CubeMapFace without range-checking; passing an uninitialized CubeMapFace field (defaults to 0 = PositiveX, so this is rare); computing a face from math that overflows the enum bounds.","commonSituations":"Dynamic face selection in cube-map rendering where the index is computed from a direction vector and not clamped; passing a raw int cast from an external data source.","solutions":["Clamp or validate the face value to the CubeMapFace enum range before constructing the binding.","Use a switch/mapping from your computed index to an explicit CubeMapFace value.","Ensure the variable is assigned from CubeMapFace members, not arbitrary integers."],"exampleFix":"// before\nvar face = (CubeMapFace)computedIndex; // could be out of range\nvar binding = new RenderTargetBinding(_cube, face);\n\n// after\nif (computedIndex < 0 || computedIndex > 5)\n    throw new ArgumentOutOfRangeException(nameof(computedIndex));\nvar face = (CubeMapFace)computedIndex;\nvar binding = new RenderTargetBinding(_cube, face);","handlingStrategy":"validation","validationCode":"if (cubeMapFace < CubeMapFace.PositiveX || cubeMapFace > CubeMapFace.NegativeZ)\n    throw new ArgumentOutOfRangeException(nameof(cubeMapFace));\nvar binding = new RenderTargetBinding(renderTarget, cubeMapFace);","typeGuard":"static bool IsValidCubeFace(CubeMapFace f) => f >= CubeMapFace.PositiveX && f <= CubeMapFace.NegativeZ;","tryCatchPattern":null,"preventionTips":["Never cast arbitrary ints to CubeMapFace without a range check.","Map computed face indices to explicit CubeMapFace members.","Clamp directional face-selection math to [0,5]."],"tags":["monogame","graphics","cubemap","argumentoutofrangeexception","enum-validation"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}