{"record":{"id":"71df0502376f81d0","repo":"stride3d/stride","slug":"the-region-s-width-regiontocheck-width-cannot-be-greater","errorCode":null,"errorMessage":"The region's width [{regionToCheck.Width}] cannot be greater than the mip-level's width [{width}]","messagePattern":"The region's width \\[(.+?)\\] cannot be greater than the mip-level's width \\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.cs","lineNumber":1465,"sourceCode":"        public unsafe void SetData<TData>(CommandList commandList, ReadOnlySpan<TData> fromData, int arrayIndex = 0, int mipLevel = 0, ResourceRegion? region = null) where TData : unmanaged\n        {\n            ArgumentNullException.ThrowIfNull(commandList);\n\n            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","sourceCodeStart":1447,"sourceCodeEnd":1483,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.cs#L1447-L1483","documentation":"Thrown by Texture upload/copy methods when a ResourceRegion's Width exceeds the mip-level's width. GPU textures are tightly sized per mip level, so a region larger than the mip cannot be addressed. The library validates regions up front with ArgumentOutOfRangeException before issuing the GPU copy.","triggerScenarios":"Calling a Texture method (e.g. SetData with a region parameter) passing a ResourceRegion whose Width is greater than the width of the mip level selected by mipLevel, e.g. using mip-level-0 dimensions for a smaller mip.","commonSituations":"Uploading partial texture data while ignoring that mipLevel shrinks width; passing full-size regions to mip 2+; hard-coded region sizes that assumed a fixed resolution texture.","solutions":["Compute the mip-level width (max(1, width >> mipLevel)) and clamp or resize the ResourceRegion to it.","Pass mipLevel 0 or a region derived from the actual mip dimensions.","Use the full texture (null region) if a sub-region is not needed."],"exampleFix":"// before\nvar region = new ResourceRegion(0, 0, 0, textureWidth, textureHeight, 1);\ntexture.SetData(commandList, data, arrayIndex: 0, mipLevel: 2, region);\n// after\nint mipWidth = Math.Max(1, textureWidth >> 2);\nint mipHeight = Math.Max(1, textureHeight >> 2);\nvar region = new ResourceRegion(0, 0, 0, mipWidth, mipHeight, 1);\ntexture.SetData(commandList, data, arrayIndex: 0, mipLevel: 2, region);","handlingStrategy":"validation","validationCode":"int mipWidth = Math.Max(1, texture.Width >> mipLevel);\nif (region != null && region.Width > mipWidth)\n    throw new InvalidOperationException($\"Region width {region.Width} exceeds mip {mipLevel} width {mipWidth}\");","typeGuard":null,"tryCatchPattern":"try { texture.SetData(cmd, data, arrayIndex, mipLevel, region); }\ncatch (ArgumentOutOfRangeException e) when (e.ParamName == \"region\") { log.Error(\"Texture region exceeds mip dimensions\", e); }","preventionTips":["Always derive regions from the mip-level dimensions, never from the base resolution.","Use texture.Description.GetMipLevelDimensions(mipLevel) style helpers.","Prefer full-sub-resource updates (null region) unless partial updates are required."],"tags":["graphics","argument-out-of-range","texture"],"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"}