{"record":{"id":"b5a2c730076c1404","repo":"stride3d/stride","slug":"value-must-be-0-texture-vulkan","errorCode":null,"errorMessage":"Value must be > 0","messagePattern":"Value must be > 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs","lineNumber":690,"sourceCode":"            if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && (description.Flags & TextureFlags.DepthStencil) == 0 && description.Format.IsCompressed)\n            {\n                description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount);\n            }\n            return description;\n        }\n\n        /// <summary>\n        /// Calculates the mip level from a specified size.\n        /// </summary>\n        /// <param name=\"size\">The size.</param>\n        /// <param name=\"minimumSizeLastMip\">The minimum size of the last mip.</param>\n        /// <returns>The mip level.</returns>\n        /// <exception cref=\"ArgumentOutOfRangeException\">Value must be > 0;size</exception>\n        private static int CalculateMipCountFromSize(int size, int minimumSizeLastMip = 4)\n        {\n            if (size <= 0)\n            {\n                throw new ArgumentOutOfRangeException(\"Value must be > 0\", \"size\");\n            }\n\n            if (minimumSizeLastMip <= 0)\n            {\n                throw new ArgumentOutOfRangeException(\"Value must be > 0\", \"minimumSizeLastMip\");\n            }\n\n            int level = 1;\n            while ((size / 2) >= minimumSizeLastMip)\n            {\n                size = Math.Max(1, size / 2);\n                level++;\n            }\n            return level;\n        }\n\n        /// <summary>\n        /// Calculates the mip level from a specified width,height,depth.","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs#L672-L708","documentation":"CalculateMipCountFromSize computes the number of mip levels for a texture dimension. It throws ArgumentOutOfRangeException when the supplied size is zero or negative, because mip level math is undefined for non-positive dimensions.","triggerScenarios":"Calling CalculateMipCountFromSize (directly or via texture mip-count calculation during texture creation) with size <= 0 — e.g. a TextureDescription with Width, Height, or Depth of 0 or a negative value.","commonSituations":"A texture description where one dimension was left at 0 (uninitialized struct default), or computed dimension became 0 after a bad scale/divide operation before creating the texture.","solutions":["Ensure texture description dimensions (Width/Height/Depth) are positive before creating the texture","Clamp or validate the size parameter before calling CalculateMipCountFromSize","Check upstream code that computes dimensions (scaling, division) so it never yields 0"],"exampleFix":"// before\nvar mipCount = Texture.CalculateMipCountFromSize(desc.Width);\n// after\nif (desc.Width <= 0) throw new ArgumentException(\"Width must be > 0\");\nvar mipCount = Texture.CalculateMipCountFromSize(desc.Width);","handlingStrategy":"validation","validationCode":"if (size <= 0) throw new ArgumentException(\"size must be > 0\");\nvar mipCount = Texture.CalculateMipCountFromSize(size);","typeGuard":"bool IsValidSize(int s) => s > 0;","tryCatchPattern":"try { mipCount = Texture.CalculateMipCountFromSize(size); }\ncatch (ArgumentOutOfRangeException) { mipCount = 1; /* no mips */ }","preventionTips":["Validate Width/Height/Depth immediately after building TextureDescription","Avoid computing dimensions with unguarded division/subtraction"],"tags":["graphics","mipmap","argument","validation"],"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"}