stride3d/stride · error · ArgumentOutOfRangeException
Value must be > 0
Error message
Value must be > 0
What it means
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.
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
Example fix
// before
var mipCount = Texture.CalculateMipCountFromSize(desc.Width);
// after
if (desc.Width <= 0) throw new ArgumentException("Width must be > 0");
var mipCount = Texture.CalculateMipCountFromSize(desc.Width); Defensive patterns
Strategy: validation
Validate before calling
if (size <= 0) throw new ArgumentException("size must be > 0");
var mipCount = Texture.CalculateMipCountFromSize(size); Type guard
bool IsValidSize(int s) => s > 0;
Try / catch
try { mipCount = Texture.CalculateMipCountFromSize(size); }
catch (ArgumentOutOfRangeException) { mipCount = 1; /* no mips */ } Prevention
- Validate Width/Height/Depth immediately after building TextureDescription
- Avoid computing dimensions with unguarded division/subtraction
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expecting a single extension
- Extension contains invalid characters
- 's must be finite and greater than zero
- Invalid mipmap level
- MipLevels must be <=
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/b5a2c730076c1404.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs:690
if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && (description.Flags & TextureFlags.DepthStencil) == 0 && description.Format.IsCompressed)
{
description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount);
}
return description;
}
/// <summary>
/// Calculates the mip level from a specified size.
/// </summary>
/// <param name="size">The size.</param>
/// <param name="minimumSizeLastMip">The minimum size of the last mip.</param>
/// <returns>The mip level.</returns>
/// <exception cref="ArgumentOutOfRangeException">Value must be > 0;size</exception>
private static int CalculateMipCountFromSize(int size, int minimumSizeLastMip = 4)
{
if (size <= 0)
{
throw new ArgumentOutOfRangeException("Value must be > 0", "size");
}
if (minimumSizeLastMip <= 0)
{
throw new ArgumentOutOfRangeException("Value must be > 0", "minimumSizeLastMip");
}
int level = 1;
while ((size / 2) >= minimumSizeLastMip)
{
size = Math.Max(1, size / 2);
level++;
}
return level;
}
/// <summary>
/// Calculates the mip level from a specified width,height,depth.View on GitHub (pinned to 96fad776d2)