stride3d/stride · error · ArgumentException
The Texture must be a Render Target
Error message
The Texture must be a Render Target
What it means
EnsureRenderTarget is a guard extension that verifies a Texture was created with TextureFlags.RenderTarget. Stride throws ArgumentException when a non-null texture passed in does not have IsRenderTarget set, because operations that treat the texture as a render target (binding it as output) are only valid for render-target textures.
Solutions
- Recreate the texture with TextureFlags.RenderTarget included in the flags argument.
- If the texture must be both sampled and rendered to, use TextureFlags.RenderTarget | TextureFlags.ShaderResource.
- If passing null is legitimate, the call already returns null; only fix non-null non-render-target textures.
Example fix
// before var tex = Texture.New2D(device, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource); tex.EnsureRenderTarget(); // after var tex = Texture.New2D(device, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget); tex.EnsureRenderTarget();
Defensive patterns
Strategy: validation
Validate before calling
if (texture is { IsRenderTarget: false })
throw new InvalidOperationException("Texture must be created with TextureFlags.RenderTarget"); Type guard
static bool IsRenderTarget(Texture? t) => t is { IsRenderTarget: true }; Try / catch
try { tex.EnsureRenderTarget(); }
catch (ArgumentException ex)
{
logger.LogError(ex, "Texture {Name} is not a render target", tex.Name);
tex = RecreateAsRenderTarget(tex);
} Prevention
- Always pass TextureFlags.RenderTarget when a texture will be bound as an output.
- Centralize texture creation in a factory that enforces required flags.
- Check IsRenderTarget in debug asserts before render-pass setup.
When it happens
Trigger: Calling texture.EnsureRenderTarget() on a texture created without TextureFlags.RenderTarget (e.g. a plain ShaderResource texture created via Texture.New2D without the flag, or a texture loaded from file).
Common situations: Creating a depth/color buffer for post-processing but forgetting the RenderTarget flag; reusing a texture loaded from disk as a render output; flag changes after upgrading Stride versions.
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 Z slice index
- Custom strides is not supported with packed PixelFormats
- Invalid texture datas. First dimension must be equal to 6
- The length and stride of destination does not match the…
- The length and stride of source does not match the vertices…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/024f3856a7c2cf88.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Texture.Extensions.cs:81
description.Format = Texture.ComputeShaderResourceFormatFromDepthFormat(description.Format); // TODO: review this
if (description.Format == PixelFormat.None)
throw new NotSupportedException("This Depth-Stencil format is not supported");
description.Flags = TextureFlags.ShaderResource;
return Texture.New(texture.GraphicsDevice, description);
}
/// <summary>
/// Verifies that a given <see cref="Texture"/> is a Render Target.
/// </summary>
/// <param name="texture"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static Texture EnsureRenderTarget(this Texture texture)
{
if (texture is not null && !texture.IsRenderTarget)
{
throw new ArgumentException("The Texture must be a Render Target", nameof(texture));
}
return texture;
}
/// <summary>
/// Creates a <see cref="Texture"/> from image file data.
/// </summary>
/// <param name="graphicsDevice">The graphics device in which to create the Texture.</param>
/// <param name="data">The image file data.</param>
/// <returns>The created Texture.</returns>
public static Texture FromFileData(GraphicsDevice graphicsDevice, byte[] data)
{
Texture result;
var loadAsSRgb = graphicsDevice.ColorSpace == ColorSpace.Linear;
using (var imageStream = new MemoryStream(data))
{View on GitHub (pinned to 96fad776d2)