Hello, we discovered a problem with the spine-ts runtime. When displaying our asset, we would receive this error in Chrome:
[.WebGL-000031B603EFE200] GL_INVALID_OPERATION: Error: 0x00000502, in ....\third_party\angle\src\libANGLE\renderer\d3d\VertexDataManager.cpp, reserveSpaceForAttrib:520. Internal error: 0x00000502: Vertex buffer is not big enough for the draw call.
WebGL: INVALID_VALUE: bufferSubData: srcOffset + length too large
Debugging it, I was able to track down the issue to the MeshBatcher.canBatch method. It has two bugs, which are causing it to erroneously report "true" (indicating it has space), when in fact it does not.
Here's the original method:
canBatch(verticesLength, indicesLength) {
if (this.indicesLength + indicesLength >= this.indices.byteLength / 2)
return false;
if (this.verticesLength + verticesLength >= this.vertices.byteLength / 2)
return false;
return true;
}
Bug 1:
if (this.verticesLength + verticesLength >= this.vertices.byteLength / 2)
This line is dividing the byteLength by 2 to get the number of floats in the buffer. But the floats are 32-bits long, so you must divide by 4.
Bug 2: The "verticesLength" field is really a number of floats, not vertices. SkeletonMesh is passing in a value that assumes that are SkeletonMesh.VERTEX_SIZE (8) floats per vertex. But from MeshBatcher's perspective, vertices have MeshBatcher.VERTEX_SIZE (9) floats per vertex. If you look down in the batch method, you can see that for every 8 floats passed in, 9 floats are added to the MeshBatcher (with the uniform 'z' value getting stamped on each vertex).
I'm not sure what the most elegant fix is, but I calculated a "vertLength3D" value in canBatch, to work out the number of floats of actual space that are implied by the submitted value, and then used that in the comparison:
let vertLength3D = verticesLength * (MeshBatcher.VERTEX_SIZE / SkeletonMesh.VERTEX_SIZE);
and then
if (this.verticesLength + vertLength3D >= this.vertices.byteLength / 4)
If it's helpful I could try to make a PR against the spine-runtimes repository in github. Thanks.