stride3d/stride · error · ArgumentOutOfRangeException

maxTexcoord must be >= 0

Error message

maxTexcoord must be >= 0

What it means

The core overload throws ArgumentOutOfRangeException('maxTexcoord', 'maxTexcoord must be >= 0') when the requested maximum texture-coordinate index is negative. maxTexcoord bounds how many TEXCOORD slots get duplicated.

Solutions

  1. Pass a positive count (default 9) or omit the parameter to use the default.
  2. Fix the config/sentinel logic so 'auto' maps to a valid value rather than -1.
  3. Validate the value before the call.

Example fix

// before
var result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, 0, stride, maxTexcoord: -1);
// after
var result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, 0, stride); // default maxTexcoord = 9
Defensive patterns

Strategy: validation

Validate before calling

if (maxTexcoord < 0) maxTexcoord = 9; // library default

Try / catch

try { var r = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, offset, stride, maxTexcoord); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "maxTexcoord") { /* clamp to default 9 */ }

Prevention

When it happens

Trigger: Calling GenerateMultiTextureCoordinates with maxTexcoord < 0 — e.g. a config value that should have defaulted to 9 but was set to -1 to mean 'auto'.

Common situations: Using -1 as a sentinel for 'unlimited'; reading maxTexcoord from bad settings/config; passing a wrong variable into the parameter.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/27f9c5c08fc376c9. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/VertexHelper.cs:124

        /// <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;

            // Use R16G16_SNorm as it is supported from HW Level 9.1
            // See https://msdn.microsoft.com/en-us/library/windows/desktop/ff471324%28v=vs.85%29.aspx

View on GitHub (pinned to 96fad776d2)