Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:06:26+00:00 2026-06-04T15:06:26+00:00

I had a bug that took me quite some time to fix. I kept

  • 0

I had a bug that took me quite some time to fix.
I kept getting EXC_BAD_ACCESS and a reference to a memmove error without any further description until I commented the following line:

[self loadShaders];

glGenVertexArraysOES(1, &_vao);
glBindVertexArrayOES(_vao);

// Vertex Buffer
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);

glEnableVertexAttribArray(ATTRIB_TEXTURE);
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 7));

// Index Buffer
glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,0);  

////////// COMMENTED THIS ONE //////////////
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);//
////////////////////////////////////////////

glBindVertexArrayOES(0);

I thought binding a buffer to 0 meant unbinding it, so I really cant understand how would that made my app crash.

Thanks for the information! I just do not stay with this concern…

My structures:

const Vertex Vertices[4] = {
    {{0.75, -1, 0}, {1, 0, 0, 1},     {0.125, 0.833496}},
    {{0.75, 1, 0}, {0, 1, 0, 1},      {0.125, 1}},
    {{-0.75, 1, 0}, {0, 0, 1, 1},     {0,     1}},
    {{-0.75, -1, 0}, {0, 0, 0, 1},    {0,     0.833496}},
};

const GLushort Indices[6] =
{
    0, 1, 2,
    2, 3, 0
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:06:27+00:00Added an answer on June 4, 2026 at 3:06 pm

    From your code, it looks as if this function is in some initialization routine, where you initialize your attribute data, which gets stored in the bound VAO, so that when drawing you only need to bind the VAO.

    A VAO in turn encapsulates all the state needed for drawing VBOs, which is the enabled flags of your attributes (set by gl(En/Dis)ableVertexAttribArray), the attribute sources and properties (set with glVertexAttribPointer), and the currently bound index buffer (set with glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)). Note that it doesn’t store the currently bound vertex buffer, as this information is stored in the attribute state.

    So what happens is, that you create and bind the index buffer, set its data, then unbind it, with the VAO still active. So the VAO state will store a GL_ELEMENT_ARRAY_BUFFER binding of 0. When you now draw something with

    glBindVertexArrayOES(_vao);
    glDrawElements(...);
    

    there is no buffer bound and the glDrawElements fails, as VAOs don’t work with client side arrays. You either have to use a VBO for the index data or draw non-indexed primitives (with glDrawArrays).

    Neither will

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
    glBindVertexArrayOES(_vao);
    glDrawElements(...);
    

    work, because the bound index buffer is overwritten by the VAO when it gets bound (whose index buffer is 0). It would work if you first bind the VAO and then the index buffer, but that would only circumvent the problem.

    Conceptually the bound GL_ELEMENT_ARRAY_BUFFER is part of the VAO state, so you should not bind it to 0 in your VAO initialization routine (only if you don’t need any index data). And neither are you allowed to use client side arrays for index or vertex data when using VAOs. If you don’t want to draw indexed geometry though, just use glDrawArrays instead of glDrawElements, but then the index buffer is obsolete, anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this nasty bug that disappeared in the past but now after quite
Recently I had to fix a bug that was reported from the field. While
I just grappled with an annoying, extremely persistent bug that had me scratching my
In a recent project, I had the pleasure of troubleshooting a bug that involved
We've all had them, errors or bugs that have lost us lots of time.
I noticed that a site I'm maintaining had a little layout bug in FF/IE8/Chrome
I had a bug that caused an integer overflow, resulting in wrong (negative) timestamps
I had a bug in my code that went like this. char desc[25]; char
I ran into a bug that was bothering me. I had JObject that I
I had a bug in my application that cause a number of messages to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.