glDrawElements causes EXC_BAD_ACCESS on iOS

11 posts / 0 new
Last post
homer_simpson
homer_simpson's picture
Offline
Joined: 9 Dec 2011
Posts:
glDrawElements causes EXC_BAD_ACCESS on iOS

Hi, i try to implement a OpenGL ES2 rendering engine, and what ever I do I get "EXC_BAD_ACCESS" when calling glDrawElements in my draw function. I use a vertex buffer object for the vertex data and one for the indices.

Here is the init function:

// generate the buffers
  GL_CHECK(glGenBuffers(1, &_vbo));
  GL_CHECK(glGenBuffers(1, &_ibo));

  // vertex data
  int vertexcount = 8;
  int structsize  = sizeof(VertexData);
  LOG_TRACE("number of vertices: %d, size of vertexdata struct: %d", vertexcount, structsize);
  GLsizeiptr sizeVertexData = sizeof(VertexData)* vertexcount;
  LOG_TRACE("sizeVertexData=%d", sizeVertexData);
  // trace the first 3 variables of container
  LOG_TRACE("vertexdata, first 3 values: x=%f|y=%f|z=%f", aVertices[0].px, aVertices[0].py, aVertices[0].pz);
  GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _vbo));
  GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeVertexData, &aVertices[0], GL_STATIC_DRAW ));

  // vertex indices
  GLsizeiptr sizeVertexIndex = sizeof(unsigned short)*12*3;
  LOG_TRACE("sizeVertexIndex=%d", sizeVertexIndex);
  // trace the first 3 variables of container
  LOG_TRACE("faceindices, first 3 values: A=%d|B=%d|C=%d", aIndices[0], aIndices[1], aIndices[2]);
  GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo));
  GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeVertexIndex, &aIndices[0], GL_STATIC_DRAW ));

  // release them
  GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
  GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));


  _iLocPosition     = shaderProgram()->attributeLocation("a_position");  
  LOG_DEBUG("_iLocPosition=%d", _iLocPosition);
  _iLocColor        = shaderProgram()->attributeLocation("a_color");
  LOG_DEBUG("_iLocColor=%d", _iLocColor);
  //_iLocNormal       = shaderProgram()->attributeLocation("a_normal");

  _iLocModelMatrix  = shaderProgram()->uniformLocation("u_modelMatrix");
  LOG_DEBUG("_iLocModelMatrix=%d", _iLocModelMatrix);

And here is the draw function:

float  m[16];
  Matrix4X4C modelMat = modelMatrix();
  modelMat.Rotate(_zRot, _xRot, _yRot);
  setModelMatrix(modelMat);
  modelMat.GetOpenGL(m);
  GL_CHECK(glUniformMatrix4fv(_iLocModelMatrix, 1, GL_FALSE, m));
  //LOG_TRACE("setting model matrix into shader to uniform id: %d", _iLocModelMatrix);
  //shaderProgram()->bind();

  // bind the buffers
  //LOG_TRACE("bind VBO & IBO");
  GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _vbo));
  GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo));

  //LOG_TRACE("enable Vertex array for attribute: %d", _iLocPosition);
  GL_CHECK(glEnableVertexAttribArray(_iLocPosition));    
  //LOG_TRACE("enable Vertex array for attribute: %d", _iLocColor);
  GL_CHECK(glEnableVertexAttribArray(_iLocColor));
  //GL_CHECK(glEnableVertexAttribArray(_iLocNormal));


  void* offset = BUFFER_OFFSET(0);
  GL_CHECK(glVertexAttribPointer(_iLocPosition, VERTEX_POS_SIZE,    GL_FLOAT, GL_FALSE, sizeof(VertexData), offset)); 
  offset = BUFFER_OFFSET(VERTEX_POS_SIZE*VERTEX_ELEMENT_TYPE_SIZE);
  GL_CHECK(glVertexAttribPointer(_iLocColor,    VERTEX_COLOR_SIZE,  GL_FLOAT, GL_FALSE, sizeof(VertexData), offset));
  //GL_CHECK(glVertexAttribPointer(_iLocNormal,   VERTEX_NORMAL_SIZE, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(VERTEX_POS_SIZE*VERTEX_ELEMENT_TYPE_SIZE)));  

  GL_CHECK(glDrawElements(GL_TRIANGLES, 12*3, GL_UNSIGNED_SHORT, 0));

  //GL_CHECK(glDisableVertexAttribArray(_iLocNormal));
  GL_CHECK(glDisableVertexAttribArray(_iLocPosition));  
  GL_CHECK(glDisableVertexAttribArray(_iLocColor));

  // release them
  GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
  GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));  

The same code runs fine under Windows via the ARM OpenGL ES 2.0 emulator framework (http://www.malideveloper.com/opengl-es-20-emulator.php).

Could someone help here?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Abi Waqas
abi's picture
Offline
Mobile Wizard
Joined: 3 May 2010
Posts:

Hi Homer_Simpson,

I am not sure at the moment if I am pointing you the right direction but I have seen the same error for ios devices and the bug already has been fired. We are working on it and hopefully it will be fixed in coming days. Please take a look at this bug reported on MoSync Issue tracker and I hope it helps you.
http://jira.mosync.com/browse/MOSYNC-1427

Cheers, A
Abi Waqas

homer_simpson
homer_simpson's picture
Offline
Joined: 9 Dec 2011
Posts:

Hi,

i have rewritten the code, to not using Vertex Buffer Objects, then it works with glDrawElements.
So it seams there is a problem in Mosync when using VBO's in OpenGL.

Abi Waqas
abi's picture
Offline
Mobile Wizard
Joined: 3 May 2010
Posts:

Sounds Interesting,

Will look into it.

Abi Waqas

Abi Waqas
abi's picture
Offline
Mobile Wizard
Joined: 3 May 2010
Posts:

Alright,
I have created the issue on Jira. I was thinking maybe you can either reply here or can put directly into Jira a little more information about the MoSync build you were running on while you encountered this problem.
Thanks for pointing this out for us.

Abi Waqas

homer_simpson
homer_simpson's picture
Offline
Joined: 9 Dec 2011
Posts:

Hi Abi,

I have tested this with the official 2.7 release and also tried a nightly build (MoSyncWindows-111221-1814.exe) both have the same crashes.

Daniel

Abi Waqas
abi's picture
Offline
Mobile Wizard
Joined: 3 May 2010
Posts:

Okay and thanks for your time, effort and input. I am sorry I missed the link to the issue I created. I now will put this information into the issue myself as I have to punish myself now :P. And I shall post the link.

Regards,
Abi Waqas

Abi Waqas
abi's picture
Offline
Mobile Wizard
Joined: 3 May 2010
Posts:

Now here is the link to the issue reported

http://jira.mosync.com/browse/MOSYNC-1431

homer_simpson
homer_simpson's picture
Offline
Joined: 9 Dec 2011
Posts:

Hi Abi,

if you need further information, or if you have something to test, then you can post into this thread and I will try it out.

Daniel

Niklas Nummelin
niklas's picture
Offline
Mobile Wizard
Joined: 18 Dec 2007
Posts:

It is now fixed.

// Niklas

homer_simpson
homer_simpson's picture
Offline
Joined: 9 Dec 2011
Posts:
niklas wrote:

It is now fixed.

// Niklas

Thanks Niklas, for your work.
I will test this the next few weeks.

Daniel