{"record":{"id":"b5429aa48fbbd8f5","repo":"stride3d/stride","slug":"vertexstride-must-be-0","errorCode":null,"errorMessage":"vertexStride must be >= 0","messagePattern":"vertexStride must be >= 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/VertexHelper.cs","lineNumber":123,"sourceCode":"        /// </exception>\n        /// <exception cref=\"System.ArgumentOutOfRangeException\">\n        /// vertexCount;vertexCount must be > 0\n        /// or\n        /// vertexStride;vertexStride must be >= 0\n        /// or\n        /// maxTexcoord;maxTexcoord must be >= 0\n        /// </exception>\n        /// <exception cref=\"System.InvalidOperationException\">The vertex buffer must contain at least the TEXCOORD</exception>\n        /// <remarks>\n        /// The original vertex buffer must contain at least a TEXCOORD[0-9] attribute in order for this method to work.\n        /// This method will copy the value of the first existing TEXCOORD found in the vertex buffer to the newly created TEXCOORDS.\n        /// </remarks>\n        public static unsafe VertexTransformResult GenerateMultiTextureCoordinates(VertexDeclaration vertexDeclaration, IntPtr vertexBufferData, int vertexCount, int vertexOffset, int vertexStride, int maxTexcoord = 9)\n        {\n            if (vertexDeclaration == null) throw new ArgumentNullException(\"vertexDeclaration\");\n            if (vertexBufferData == IntPtr.Zero) throw new ArgumentNullException(\"vertexBufferData\");\n            if (vertexCount <= 0) throw new ArgumentOutOfRangeException(\"vertexCount\", \"vertexCount must be > 0\");\n            if (vertexStride < 0) throw new ArgumentOutOfRangeException(\"vertexStride\", \"vertexStride must be >= 0\");\n            if (maxTexcoord < 0) throw new ArgumentOutOfRangeException(\"maxTexcoord\", \"maxTexcoord must be >= 0\");\n\n            // Get the stride from the vertex declaration if necessary\n            if (vertexStride == 0)\n            {\n                vertexStride = vertexDeclaration.VertexStride;\n            }\n\n            // TODO: Usage index in key\n            var offsetMapping = vertexDeclaration\n                .EnumerateWithOffsets()\n                .ToDictionary(x => x.VertexElement.SemanticAsText, x => x.Offset);\n\n            var newVertexElements = new List<VertexElement>();\n\n            int vertexUVOffset = -1;\n\n            // Use R16G16_SNorm as it is supported from HW Level 9.1","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/VertexHelper.cs#L105-L141","documentation":"The core overload throws ArgumentOutOfRangeException('vertexStride', 'vertexStride must be >= 0') when a negative stride is passed. A negative stride would make pointer arithmetic walk outside the buffer; zero is allowed and means 'take stride from the declaration'.","triggerScenarios":"Passing a negative vertexStride — typically from a miscomputed sizeof/offset or a corrupted stride variable.","commonSituations":"Hand-calculated stride in interop code; stride read from a malformed asset; sign error after refactoring offsets.","solutions":["Pass the correct positive stride, or 0 to let the method use vertexDeclaration.VertexStride.","Compute the stride from Unsafe.SizeOf<T>() or the declaration instead of manual math.","Validate the stride before the call."],"exampleFix":"// before\nint stride = ComputeStrideSomehow(); // negative\nvar result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, 0, stride);\n// after\nint stride = 0; // 0 = derive from declaration\nvar result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, 0, stride);","handlingStrategy":"validation","validationCode":"if (vertexStride < 0) vertexStride = 0; // 0 lets the declaration supply the stride","typeGuard":null,"tryCatchPattern":"try { var r = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, offset, stride); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"vertexStride\") { /* pass 0 or the declaration stride */ }","preventionTips":["Prefer passing 0 and letting vertexDeclaration.VertexStride define it","Use Unsafe.SizeOf<T>() rather than manual stride math"],"tags":["argument-out-of-range","graphics","stride"],"backgroundTag":"argument-out-of-range","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"}