{"record":{"id":"1ed72e69d42e758b","repo":"stride3d/stride","slug":"the-region-s-depth-regiontocheck-depth-cannot-be-greater","errorCode":null,"errorMessage":"The region's depth [{regionToCheck.Depth}] cannot be greater than the mip-level's depth [{depth}]","messagePattern":"The region's depth \\[(.+?)\\] cannot be greater than the mip-level's depth \\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.cs","lineNumber":1469,"sourceCode":"            if (region.HasValue && Usage != GraphicsResourceUsage.Default)\n                throw new ArgumentException($\"A region can only be specified for Textures with {nameof(GraphicsResourceUsage)}.{nameof(GraphicsResourceUsage.Default)}\", nameof(region));\n\n            // Get a description for the specified mip-level\n            ref readonly var mipmap = ref GetMipMapDescription(mipLevel);\n\n            int width = mipmap.Width;\n            int height = mipmap.Height;\n            int depth = mipmap.Depth;\n\n            // If we are using a region, then check that parameters are fine\n            if (region is ResourceRegion regionToCheck)\n            {\n                if (regionToCheck.Width > width)\n                    throw new ArgumentOutOfRangeException(nameof(region), $\"The region's width [{regionToCheck.Width}] cannot be greater than the mip-level's width [{width}]\");\n                if (regionToCheck.Height > height)\n                    throw new ArgumentOutOfRangeException(nameof(region), $\"The region's height [{regionToCheck.Height}] cannot be greater than the mip-level's height [{height}]\");\n                if (regionToCheck.Depth > depth)\n                    throw new ArgumentOutOfRangeException(nameof(region), $\"The region's depth [{regionToCheck.Depth}] cannot be greater than the mip-level's depth [{depth}]\");\n\n                width = regionToCheck.Width;\n                height = regionToCheck.Height;\n                depth = regionToCheck.Depth;\n            }\n\n            var sizePerElement = Format.SizeInBytes;\n\n            // Compute actual pitch\n            Image.ComputePitch(Format, width, height, out var rowStride, out var textureDepthStride, out width, out height);\n\n            // Size Of actual texture data\n            int sizeOfTextureData = textureDepthStride * depth;\n\n            int fromDataSizeInBytes = fromData.Length * sizeof(TData);\n\n            // Check largestSize validity of data to copy from\n            if (fromDataSizeInBytes < sizeOfTextureData)","sourceCodeStart":1451,"sourceCodeEnd":1487,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.cs#L1451-L1487","documentation":"Thrown when a ResourceRegion's Depth exceeds the mip-level depth. For 3D textures (or arrays treated as depth) the region must fit within the mip-level's depth extent. The check guards the GPU sub-resource copy from out-of-bounds access.","triggerScenarios":"Calling a Texture data method with a ResourceRegion whose Depth is larger than the volume texture's mip-level depth, e.g. region depth of 16 on a 3D texture whose mip is only 4 slices deep.","commonSituations":"Uploading sub-volumes of 3D textures with depth taken from the base level rather than the mip level; array-slice confusion where arraySize is treated as depth.","solutions":["Clamp region depth to max(1, mipDepth >> mipLevel) for the target mip.","Verify you are using arrayIndex (2D arrays) rather than region Depth to select slices.","Pass the whole sub-resource (null region) when updating all slices."],"exampleFix":"// before\nvar region = new ResourceRegion(0, 0, 0, w, h, volumeDepth); // base-level depth\ntexture.SetData(cmd, data, 0, mipLevel: 3, region);\n// after\nint mipDepth = Math.Max(1, volumeDepth >> 3);\nvar region = new ResourceRegion(0, 0, 0, w, h, mipDepth);\ntexture.SetData(cmd, data, 0, mipLevel: 3, region);","handlingStrategy":"validation","validationCode":"int mipDepth = Math.Max(1, texture.Depth >> mipLevel);\nif (region != null && region.Depth > mipDepth)\n    throw new InvalidOperationException($\"Region depth {region.Depth} exceeds mip {mipLevel} depth {mipDepth}\");","typeGuard":null,"tryCatchPattern":"try { texture.SetData(cmd, data, arrayIndex, mipLevel, region); }\ncatch (ArgumentOutOfRangeException e) when (e.ParamName == \"region\") { log.Error(\"Region depth too large for mip\", e); }","preventionTips":["For 2D array textures use arrayIndex, not region Depth, to select slices.","Clamp Depth to the mip-level depth for 3D textures.","Test 3D uploads on the smallest mip first."],"tags":["graphics","argument-out-of-range","texture3d"],"backgroundTag":"argument-out-of-range","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"}