'glDrawArrays: attempt to access out of range vertices in attribute 1' on Emscripten/OpenGL code (works in native C++)
<p>I have narrowed down the issue to this.  I have two attributes pointed at the exact same data.  This works fine when build in native C++.  However, when built with emscripten, the javascript console shows the following error on each frame:</p>

<pre><code>'glDrawArrays: attempt to access out of range vertices in attribute 1'
</code></pre>

<p>When I comment out the 'glEnableVertexAttribArray' line to enable the second attribute, I don't get this error.</p>

<p>Below is my code.  I'll start with the data buffer creation:</p>

<pre><code>GLfloat rectangleData[] =
{
    -.5f, -.5f,     0,1,
    -.5f, .5f,      0,0,
    .5f, .5f,       1,0,
    .5f, -.5f,      1,1,
    -.5f, -.5f,     0,1
};
glGenBuffers(1, &amp;rectangleBuffer);
glBindBuffer(GL_ARRAY_BUFFER, rectangleBuffer);
glBufferData(
        GL_ARRAY_BUFFER, sizeof(rectangleData),
        rectangleData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
</code></pre>

<p>Here is a relevant excerpt from my textured quad drawing code:</p>

<pre><code>glBindBuffer(GL_ARRAY_BUFFER, rectangleBuffer);

int vertexPosition = Shader::getParameterInfo("vertexPosition")-&gt;id;
glVertexAttribPointer(
        vertexPosition, 2, GL_FLOAT,
        GL_FALSE, 16, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vertexPosition);

int vertexTexCoord = Shader::getParameterInfo("vertexTexCoord")-&gt;id;
glVertexAttribPointer(
        vertexTexCoord, 2, GL_FLOAT,
        GL_FALSE, 16, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vertexTexCoord);

glDrawArrays(GL_TRIANGLE_FAN, 0, 5);
</code></pre>

<p>Notice that I've adjusted the second attribute to point to the same data as the first (to reduce complexity while debugging).  I'm pretty stumped here and could really use a fresh/experienced perspective.</p>

<p>EDIT: Here's what <code>BUFFER_OFFSET</code> looks like:</p>

<pre><code>#define BUFFER_OFFSET(i) ((char *)NULL + (i))
</code></pre>

<p>Source: <a href="https://stackoverflow.com/questions/23177229/how-to-cast-int-to-const-glvoid">How to cast int to const GLvoid*?</a></p>

<p>EDIT: For what it's worth, here is the equivalent Emscripten generated JS code.  I'll post any JS code this references if requested.</p>

<pre><code>dest=$rectangleData; src=2328; stop=dest+80|0; do {
HEAP32[dest&gt;&gt;2]=HEAP32[src&gt;&gt;2]|0; dest=dest+4|0; src=src+4|0; } while
((dest|0) &lt; (stop|0));
 _glGenBuffers(1,(2300|0));
 $30 = HEAP32[2300&gt;&gt;2]|0;
 _glBindBuffer(34962,($30|0));
 _glBufferData(34962,80,($rectangleData|0),35044);
 _glBindBuffer(34962,0);

$11 = HEAP32[2300&gt;&gt;2]|0;
 _glBindBuffer(34962,($11|0));
 $12 = (__ZN8platform6Shader16getParameterInfoEPKc(17356)|0);
 $13 = HEAP32[$12&gt;&gt;2]|0;
 $vertexPosition = $13;
 $14 = $vertexPosition;
 _glVertexAttribPointer(($14|0),2,5126,0,16,(0|0));
 $15 = $vertexPosition;
 _glEnableVertexAttribArray(($15|0));
 $16 = (__ZN8platform6Shader16getParameterInfoEPKc(17379)|0);
 $17 = HEAP32[$16&gt;&gt;2]|0;
 $vertexTexCoord = $17;
 $18 = $vertexTexCoord;
 _glVertexAttribPointer(($18|0),2,5126,0,16,(0|0));
 $19 = $vertexTexCoord;
 _glEnableVertexAttribArray(($19|0));
 _glDrawArrays(6,0,5);
</code></pre>

<p>Edit:  Better yet, I'll provide a link to the JS code running on github, and the C++ code too (it's near the bottom in "drawImage()"):</p>

<p><a href="https://rawgit.com/jon-heard/Native-WebGL-framework/c134e35ac94fdf3243a9662353ad2227f8c84b43/Native-WebGL-framework/web/index.html" rel="nofollow noreferrer">https://rawgit.com/jon-heard/Native-WebGL-framework/c134e35ac94fdf3243a9662353ad2227f8c84b43/Native-WebGL-framework/web/index.html</a></p>

<p><a href="https://github.com/jon-heard/Native-WebGL-framework/blob/c134e35ac94fdf3243a9662353ad2227f8c84b43/Native-WebGL-framework/src/platform/draw.cpp" rel="nofollow noreferrer">https://github.com/jon-heard/Native-WebGL-framework/blob/c134e35ac94fdf3243a9662353ad2227f8c84b43/Native-WebGL-framework/src/platform/draw.cpp</a></p>