stride3d/stride · error · ArgumentNullException
vertexDeclaration
Error message
vertexDeclaration
What it means
GenerateMultiTextureCoordinates requires a non-null VertexDeclaration describing the vertex layout; the library throws ArgumentNullException('vertexDeclaration') at entry if null is passed. The declaration is needed to locate the existing TEXCOORD attribute and compute strides, so it cannot proceed without it.
Solutions
- Construct or obtain the VertexDeclaration before calling (e.g. VertexDeclaration.New(...) or from the existing mesh's VertexBuffer.Binding).
- Guard with a null check or assert before invoking the helper.
- Fix the code path that returns null for the declaration (failed asset load, uninitialized field).
Example fix
// before
var result = VertexHelper.GenerateMultiTextureCoordinates(declaration, vertexData);
// after
if (declaration == null) throw new InvalidOperationException("Vertex declaration must be built before generating multi texture coordinates");
var result = VertexHelper.GenerateMultiTextureCoordinates(declaration, vertexData); Defensive patterns
Strategy: validation
Validate before calling
if (vertexDeclaration is null) throw new InvalidOperationException("vertexDeclaration must be provided before calling GenerateMultiTextureCoordinates"); Type guard
bool HasDeclaration(VertexDeclaration d) => d is not null;
Try / catch
try { var r = VertexHelper.GenerateMultiTextureCoordinates(decl, data); } catch (ArgumentNullException ex) when (ex.ParamName == "vertexDeclaration") { /* build/assign declaration and retry */ } Prevention
- Always derive the declaration from the source mesh's vertex buffer binding
- Assert non-null declarations in mesh preprocessing pipelines
- Construct declarations with VertexDeclaration.New next to buffer creation
When it happens
Trigger: Calling VertexHelper.GenerateMultiTextureCoordinates(null, vertexBufferData) (any of the T[], byte[], or IntPtr overloads) with an uninitialized/null VertexDeclaration.
Common situations: VertexDeclaration loaded lazily or from a failed mesh import; a member field never assigned before use; refactoring moved declaration creation after the call.
Related errors
- vertexBufferData
- The relativePath argument is null or empty
- Invalid length for FourCC
- Invalid Z slice index
- The length of the destination data buffer is larger than…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/e46a21badf3e2d7e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexHelper.cs:37
// TODO: Write some unit tests!
/// <summary>
/// Generates multi texture coordinates for an existing vertex buffer. See remarks.
/// </summary>
/// <param name="vertexDeclaration">The vertex declaration.</param>
/// <param name="vertexBufferData">The vertex buffer data.</param>
/// <param name="maxTexcoord">The maximum texcoord.</param>
/// <returns>A new vertex buffer with additional texture coordinates.</returns>
/// <exception cref="System.ArgumentNullException">
/// vertexDeclaration
/// or
/// vertexBufferData
/// </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<T>(VertexDeclaration vertexDeclaration, T[] vertexBufferData, int maxTexcoord = 9) where T : unmanaged
{
if (vertexDeclaration == null) throw new ArgumentNullException("vertexDeclaration");
if (vertexBufferData == null) throw new ArgumentNullException("vertexBufferData");
var vertexStride = Unsafe.SizeOf<T>();
fixed (void* vertexBufferPtr = vertexBufferData)
return GenerateMultiTextureCoordinates(vertexDeclaration, (nint)vertexBufferPtr, vertexBufferData.Length, 0, vertexStride, maxTexcoord);
}
/// <summary>
/// Generates multi texture coordinates for an existing vertex buffer. See remarks.
/// </summary>
/// <param name="vertexDeclaration">The vertex declaration.</param>
/// <param name="vertexBufferData">The vertex buffer data.</param>
/// <param name="vertexStride">The vertex stride.</param>
/// <param name="maxTexcoord">The maximum texcoord.</param>
/// <returns>A new vertex buffer with additional texture coordinates.</returns>
/// <exception cref="System.ArgumentNullException">
/// vertexDeclaration
/// or
/// vertexBufferDataView on GitHub (pinned to 96fad776d2)