stride3d/stride · error · ArgumentOutOfRangeException
vertexCount must be > 0
Error message
vertexCount must be > 0
What it means
The core overload throws ArgumentOutOfRangeException('vertexCount', 'vertexCount must be > 0') when vertexCount is zero or negative. A zero-vertex buffer has nothing to transform, so the library rejects it eagerly.
Solutions
- Skip the call entirely for empty meshes (return early).
- Ensure vertexCount is computed as bufferLength / vertexStride and is positive.
- Fix the upstream logic yielding the non-positive count.
Example fix
// before var result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, vertexCount, 0, stride); // vertexCount = 0 // after if (vertexCount <= 0) return null; // or skip the transformation var result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, vertexCount, 0, stride);
Defensive patterns
Strategy: validation
Validate before calling
if (vertexCount <= 0) return null; // skip transform for empty meshes
Try / catch
try { var r = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, offset, stride); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "vertexCount") { /* skip or fix count computation */ } Prevention
- Early-return for empty meshes instead of calling the helper
- Compute vertexCount as byteLength / stride and assert it is positive
- Beware integer division truncating to 0
When it happens
Trigger: Calling GenerateMultiTextureCoordinates with vertexCount = 0 (empty mesh) or a negative value from a bad length/stride division.
Common situations: Empty meshes from failed imports; integer division rounding count to 0; off-by-one producing 0 or negative counts.
Related errors
- Invalid mipmap level
- Invalid z slice index
- Invalid array slice index
- The Graphics Resource is a Texture, but its dimension is…
- Value must be in between 1 and 32
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/5e43483941521685.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexHelper.cs:122
/// vertexBufferData
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// vertexCount;vertexCount must be > 0
/// or
/// vertexStride;vertexStride must be >= 0
/// or
/// maxTexcoord;maxTexcoord must be >= 0
/// </exception>
/// <exception cref="System.InvalidOperationException">The vertex buffer must contain at least the TEXCOORD</exception>
/// <remarks>
/// The original vertex buffer must contain at least a TEXCOORD[0-9] attribute in order for this method to work.
/// This method will copy the value of the first existing TEXCOORD found in the vertex buffer to the newly created TEXCOORDS.
/// </remarks>
public static unsafe VertexTransformResult GenerateMultiTextureCoordinates(VertexDeclaration vertexDeclaration, IntPtr vertexBufferData, int vertexCount, int vertexOffset, int vertexStride, int maxTexcoord = 9)
{
if (vertexDeclaration == null) throw new ArgumentNullException("vertexDeclaration");
if (vertexBufferData == IntPtr.Zero) throw new ArgumentNullException("vertexBufferData");
if (vertexCount <= 0) throw new ArgumentOutOfRangeException("vertexCount", "vertexCount must be > 0");
if (vertexStride < 0) throw new ArgumentOutOfRangeException("vertexStride", "vertexStride must be >= 0");
if (maxTexcoord < 0) throw new ArgumentOutOfRangeException("maxTexcoord", "maxTexcoord must be >= 0");
// Get the stride from the vertex declaration if necessary
if (vertexStride == 0)
{
vertexStride = vertexDeclaration.VertexStride;
}
// TODO: Usage index in key
var offsetMapping = vertexDeclaration
.EnumerateWithOffsets()
.ToDictionary(x => x.VertexElement.SemanticAsText, x => x.Offset);
var newVertexElements = new List<VertexElement>();
int vertexUVOffset = -1;
View on GitHub (pinned to 96fad776d2)