{"record":{"id":"5e43483941521685","repo":"stride3d/stride","slug":"vertexcount-must-be-0","errorCode":null,"errorMessage":"vertexCount must be > 0","messagePattern":"vertexCount must be > 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/VertexHelper.cs","lineNumber":122,"sourceCode":"        /// vertexBufferData\n        /// </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","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/VertexHelper.cs#L104-L140","documentation":"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.","triggerScenarios":"Calling GenerateMultiTextureCoordinates with vertexCount = 0 (empty mesh) or a negative value from a bad length/stride division.","commonSituations":"Empty meshes from failed imports; integer division rounding count to 0; off-by-one producing 0 or negative counts.","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."],"exampleFix":"// before\nvar result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, vertexCount, 0, stride); // vertexCount = 0\n// after\nif (vertexCount <= 0) return null; // or skip the transformation\nvar result = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, vertexCount, 0, stride);","handlingStrategy":"validation","validationCode":"if (vertexCount <= 0) return null; // skip transform for empty meshes","typeGuard":null,"tryCatchPattern":"try { var r = VertexHelper.GenerateMultiTextureCoordinates(decl, ptr, count, offset, stride); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"vertexCount\") { /* skip or fix count computation */ }","preventionTips":["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"],"tags":["argument-out-of-range","graphics","empty-input"],"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-15T23:17:13.987Z"}