stride3d/stride · error · InvalidOperationException
A negative number of mip maps is not allowed.
Error message
A negative number of mip maps is not allowed.
What it means
The VideoTexture constructor rejects a negative maxMipMapCount because a mip chain cannot have fewer than zero extra levels. The value is passed through to texture/sampler setup, so the constructor fails fast with InvalidOperationException when it is negative.
Solutions
- Set videoComponent.MaxMipMapCount to 0 or a positive value before allocating the texture.
- If 'auto mipmaps' was intended, pass 0 (or the maximum) rather than -1, per this API's convention.
- Audit serialized assets/prefabs containing the video component for a -1 MaxMipMapCount and fix them.
Example fix
// before videoComponent.MaxMipMapCount = -1; // 'auto' (wrong convention) videoInstance.AllocateVideoTexture(w, h); // throws // after videoComponent.MaxMipMapCount = 0; videoInstance.AllocateVideoTexture(w, h);
Defensive patterns
Strategy: validation
Validate before calling
// C#
if (maxMipMapCount < 0)
maxMipMapCount = 0; // clamp before allocating
videoInstance.AllocateVideoTexture(width, height); Try / catch
// C#
try { videoInstance.AllocateVideoTexture(w, h); }
catch (InvalidOperationException ex) when (ex.Message.Contains("mip maps"))
{
// fix videoComponent.MaxMipMapCount then retry
} Prevention
- Never use -1 as 'auto' for MaxMipMapCount; use 0 or a positive count
- Clamp mip count to Math.Max(0, value) before allocation
- Audit serialized video component assets for negative MaxMipMapCount
When it happens
Trigger: Constructing VideoTexture (directly or via VideoInstance.AllocateVideoTexture) with maxMipMapCount < 0, e.g. from videoComponent.MaxMipMapCount being set to -1 in code or a component property.
Common situations: Typo or misunderstanding of the convention (using -1 to mean 'auto'); loading a component asset where MaxMipMapCount was serialized as -1; copying a config value that another engine treats as 'unlimited'.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid video resolution.
- Destination texture is a MSAA texture.
- Source texture is not a MSAA texture.
- The Graphics Resource is a Texture, but its dimension is…
- The options specified for the Texture are not valid.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/d3035e825213105e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Video/VideoTexture.cs:39
/// Effect used to create mipmap inside the <see cref="renderTargetTexture"/>
/// </summary>
private EffectInstance effectTexture2DCopy;
private Texture originalTargetTexture;
private Texture renderTargetTexture;
private SamplerState minMagLinearMipPointSampler;
public VideoTexture(GraphicsDevice graphicsDevice, IServiceRegistry serviceRegistry, int width, int height, int maxMipMapCount)
{
if (width <= 0 || height <= 0)
{
throw new InvalidOperationException("Invalid video resolution.");
}
if (maxMipMapCount < 0)
{
throw new InvalidOperationException("A negative number of mip maps is not allowed.");
}
var effectSystem = serviceRegistry.GetSafeServiceAs<EffectSystem>();
// We want to sample mip maps using point filtering (to make sure nothing bleeds between mip maps).
minMagLinearMipPointSampler = SamplerState.New(graphicsDevice, new SamplerStateDescription(TextureFilter.MinMagLinearMipPoint, TextureAddressMode.Clamp));
// Allocate the effect for copying decoder output texture to our normal render texture
effectDecoderTextureCopy = new EffectInstance(effectSystem.LoadEffect("SpriteEffectExtTexture").WaitForResult());
effectDecoderTextureCopy.Parameters.Set(SpriteEffectExtTextureKeys.Gamma, 2.2f);
effectDecoderTextureCopy.Parameters.Set(SpriteEffectExtTextureKeys.MipLevel, 0.0f);
effectDecoderTextureCopy.Parameters.Set(SpriteEffectExtTextureKeys.Sampler, minMagLinearMipPointSampler);
effectDecoderTextureCopy.UpdateEffect(graphicsDevice);
// Allocate the effect for copying regular 2d textures:
effectTexture2DCopy = new EffectInstance(effectSystem.LoadEffect("SpriteEffectExtTextureRegular").WaitForResult());
effectTexture2DCopy.Parameters.Set(SpriteEffectExtTextureKeys.MipLevel, 0.0f);
effectTexture2DCopy.Parameters.Set(SpriteEffectExtTextureRegularKeys.Sampler, minMagLinearMipPointSampler);View on GitHub (pinned to 96fad776d2)