{"record":{"id":"28a071bbf5b452fd","repo":"stride3d/stride","slug":"a-nameof-vertexelement-overlaps-with-another-element-check","errorCode":null,"errorMessage":"A {nameof(VertexElement)} overlaps with another element. Check the element's offset","messagePattern":"A (.+?) overlaps with another element\\. Check the element's offset","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/VertexElementValidator.cs","lineNumber":110,"sourceCode":"            }\n\n            // Check for duplicate semantic names and indices\n            for (int i = 0; i < elementIndex; i++)\n            {\n                if (elements[elementIndex].SemanticName.Equals(elements[i].SemanticName) &&\n                    elements[elementIndex].SemanticIndex == elements[i].SemanticIndex)\n                {\n                    throw new ArgumentException($\"Duplicate {nameof(VertexElement)}s found with the same semantic name and index\", nameof(elements));\n                }\n            }\n\n            // Check for overlap with existing elements\n            for (int i = elementOffset; i < (elementOffset + typeSize); i++)\n            {\n                // Check for overlap with existing elements\n                if (overlapCheckArray[i] >= 0)\n                {\n                    throw new ArgumentException($\"A {nameof(VertexElement)} overlaps with another element. Check the element's offset\", nameof(elements));\n                }\n                // Mark this byte as occupied by this element\n                overlapCheckArray[i] = elementIndex;\n            }\n        }\n    }\n}\n","sourceCodeStart":92,"sourceCodeEnd":118,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/VertexElementValidator.cs#L92-L118","documentation":"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).","triggerScenarios":"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.","commonSituations":"Hand-computed offsets that forgot the previous element's full size; aliasing elements over the same data expecting swizzled reads, which the validator forbids.","solutions":["Fix the second element's offset to start after the previous element ends","Recompute all offsets by accumulating Format.SizeInBytes of preceding elements","Remove the overlapping element if the data is already covered"],"exampleFix":"// before\nnew VertexElement(\"POSITION\", 0, PixelFormat.R32G32B32_Float), // bytes 0..11\nnew VertexElement(\"NORMAL\", 8, PixelFormat.R32G32B32_Float)    // overlaps at 8..19\n// after\nnew VertexElement(\"POSITION\", 0, PixelFormat.R32G32B32_Float),\nnew VertexElement(\"NORMAL\", 12, PixelFormat.R32G32B32_Float)","handlingStrategy":"validation","validationCode":"bool NoOverlap(VertexElement[] elements) {\n    var ranges = elements.Select(e => (Start: e.Offset, End: e.Offset + e.Format.SizeInBytes)).OrderBy(r => r.Start).ToList();\n    for (int i = 1; i < ranges.Count; i++)\n        if (ranges[i].Start < ranges[i-1].End) return false;\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { VertexElementValidator.Validate(stride, elements); } catch (ArgumentException) { recomputeSequentialOffsets(); }","preventionTips":["Accumulate offsets by Format.SizeInBytes instead of hand-writing them","Never reuse an offset for a different semantic","Run the validator on declarations before creating buffers"],"tags":["graphics","vertex-declaration","overlap","layout"],"backgroundTag":"schema-validation-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}