stride3d/stride · error · InvalidOperationException
Invalid video resolution.
Error message
Invalid video resolution.
What it means
The VideoTexture constructor validates that width and height are strictly positive before creating the GPU texture and mip chain. A non-positive dimension cannot describe a valid texture, so the constructor fails fast with InvalidOperationException instead of producing a broken GraphicsResource.
Solutions
- Load/open the video first so real dimensions are known, then allocate the texture.
- Validate width and height are > 0 before constructing VideoTexture and fall back to sane defaults (e.g. 1280x720) otherwise.
- Check the source video file: re-encode or replace it if its metadata reports a zero resolution.
Example fix
// before
videoInstance.AllocateVideoTexture(videoWidth, videoHeight); // videoWidth = 0 before load
// after
if (videoWidth > 0 && videoHeight > 0)
videoInstance.AllocateVideoTexture(videoWidth, videoHeight);
else
videoInstance.AllocateVideoTexture(1280, 720); // fallback until real size known Defensive patterns
Strategy: validation
Validate before calling
// C#
if (width <= 0 || height <= 0)
throw new ArgumentOutOfRangeException(nameof(width), "Video resolution must be positive");
videoInstance.AllocateVideoTexture(width, height); Try / catch
// C#
try { videoInstance.AllocateVideoTexture(w, h); }
catch (InvalidOperationException ex) when (ex.Message == "Invalid video resolution.")
{
videoInstance.AllocateVideoTexture(1280, 720); // safe fallback
} Prevention
- Only allocate after the video metadata has been loaded and dimensions are known
- Validate width/height > 0 before any texture allocation
- Treat zero dimensions from video metadata as 'not loaded yet', not as real size
When it happens
Trigger: Constructing VideoTexture (directly or via VideoInstance.AllocateVideoTexture) with width <= 0 or height <= 0 — typically because the underlying video/texture metadata reported zero-size dimensions before the stream was opened or decoded.
Common situations: Querying video size before the media is loaded, so width/height default to 0; a corrupted or unsupported video file whose dimensions read as 0; passing unvalidated configuration values as resolution.
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
- A negative number of mip maps is not allowed.
- 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/7f89d881a1e4d0be.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Video/VideoTexture.cs:34
/// <summary>
/// Effect used to copy the <see cref="decoderOutputTexture"/> into the <see cref="renderTargetTexture"/>.
/// </summary>
private EffectInstance effectDecoderTextureCopy;
/// <summary>
/// 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);View on GitHub (pinned to 96fad776d2)