stride3d/stride · error · ArgumentException

A overlaps with another element. Check the element's offset

Error message

A {nameof(VertexElement)} overlaps with another element. Check the element's offset

What it means

Validate tracks every byte occupied by each element; if a new element's byte range intersects bytes already claimed by an earlier element, the declaration is rejected with ArgumentException because GPU input layouts require non-overlapping slots (unless intentionally aliased).

Solutions

  1. Fix the second element's offset to start after the previous element ends
  2. Recompute all offsets by accumulating Format.SizeInBytes of preceding elements
  3. Remove the overlapping element if the data is already covered

Example fix

// before
new VertexElement("POSITION", 0, PixelFormat.R32G32B32_Float), // bytes 0..11
new VertexElement("NORMAL", 8, PixelFormat.R32G32B32_Float)    // overlaps at 8..19
// after
new VertexElement("POSITION", 0, PixelFormat.R32G32B32_Float),
new VertexElement("NORMAL", 12, PixelFormat.R32G32B32_Float)
Defensive patterns

Strategy: validation

Validate before calling

bool NoOverlap(VertexElement[] elements) {
    var ranges = elements.Select(e => (Start: e.Offset, End: e.Offset + e.Format.SizeInBytes)).OrderBy(r => r.Start).ToList();
    for (int i = 1; i < ranges.Count; i++)
        if (ranges[i].Start < ranges[i-1].End) return false;
    return true;
}

Try / catch

try { VertexElementValidator.Validate(stride, elements); } catch (ArgumentException) { recomputeSequentialOffsets(); }

Prevention

When it happens

Trigger: Two elements whose [offset, offset+size) ranges intersect, e.g. a R32G32B32 at offset 0 (12 bytes) and a R32 at offset 8; or a duplicate offset reused for a different semantic.

Common situations: Hand-computed offsets that forgot the previous element's full size; aliasing elements over the same data expecting swizzled reads, which the validator forbids.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/VertexElementValidator.cs:110

            }

            // Check for duplicate semantic names and indices
            for (int i = 0; i < elementIndex; i++)
            {
                if (elements[elementIndex].SemanticName.Equals(elements[i].SemanticName) &&
                    elements[elementIndex].SemanticIndex == elements[i].SemanticIndex)
                {
                    throw new ArgumentException($"Duplicate {nameof(VertexElement)}s found with the same semantic name and index", nameof(elements));
                }
            }

            // Check for overlap with existing elements
            for (int i = elementOffset; i < (elementOffset + typeSize); i++)
            {
                // Check for overlap with existing elements
                if (overlapCheckArray[i] >= 0)
                {
                    throw new ArgumentException($"A {nameof(VertexElement)} overlaps with another element. Check the element's offset", nameof(elements));
                }
                // Mark this byte as occupied by this element
                overlapCheckArray[i] = elementIndex;
            }
        }
    }
}

View on GitHub (pinned to 96fad776d2)