rendajs / Renda

A modern rendering engine for the web.
https://rendajs.org
MIT License
10 stars 4 forks source link

Better error message when creating a VertexState with invalid arrayStride #818

Open jespertheend opened 11 months ago

jespertheend commented 11 months ago

I just created the following VertexState:

new VertexState({
    buffers: [
        {
            stepMode: "vertex",
            arrayStride: 12,
            attributes: [
                {
                    attributeType: Mesh.AttributeType.POSITION,
                    componentCount: 3,
                    format: Mesh.AttributeFormat.FLOAT32,
                    unsigned: false,
                },
            ],
        },
        {
            stepMode: "vertex",
            arrayStride: 12,
            attributes: [
                {
                    attributeType: Mesh.AttributeType.COLOR,
                    componentCount: 4,
                    format: Mesh.AttributeFormat.FLOAT32,
                    unsigned: false,
                },
            ],
        },
    ],
});

The second buffer has an array stride of 12, but a componentCount of 4. When applying it to an existing mesh using Mesh.setVertexState(), it threw the following error:

RangeError: Offset is outside the bounds of the DataView

This isn't very helpful, it should make it clear that the provided component count and format doesn't fit in the provided arrayStride.