SirYancy
SirYancy

Reputation: 167

GL Error value 1285: Out of memory

I'm trying to render a simple quad in a few different ways.

I can do this very easily when everything is stored in one class. But I want to be able to render more than a single object on the screen so I'm starting to take the code apart and put various bits of functionality in separate classes. The problem is, when I put the rendering functionality in the Entity class, I start getting an error.

This is the function, which is is a VertexArrayObject class:

public void render(){
    glBindVertexArray(vaoID);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboiID);

    this.exitOnGLError("Before render");
    glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_BYTE, 0);
    this.exitOnGLError("After render");

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glBindVertexArray(0);

    this.exitOnGLError("error rendering vao");
}

Again, all I have done is move this from the main class into a class that manages the VAO and theoretically renders it.

It's giving me error value 1285, and the error call that gets the error is the one labeled "After render". (exitOnGLError() is an error checking method).

Error 1285 apparently means "Out of memory" which is patently absurd since I'm using a 1 megabyte image file and...I just can't imagine my four vertex float buffer is filling up all my VRAM.

What else could be causing this error?

Upvotes: 3

Views: 13302

Answers (4)

Archon 808
Archon 808

Reputation: 200

FYI I had this same error, and it was caused by the fact that I failed to add the call to glBufferData, which is where you actually "send the data" to opengl.

glBufferData(GL_ARRAY_BUFFER, sizeof(GLSL_XYZNDUV_Item)*p->iNum_verts,p->pVerts,GL_STATIC_DRAW);

glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*p->iNum_tris*2,p->pIndices, GL_STATIC_DRAW);

Upvotes: 2

Lars
Lars

Reputation: 134

I've just run into the same error when rendering a .obj file with OpenGL on Android 11 (works fine on Android 9). There seems to be a bug in OpenGL making it throw the out of memory error whenever the source vertices in the .obj file are defined in the Vertex normal indices without texture coordinate indices format (f 113//113 76//76 77//77). To circumvent the error, just add a single texture coordinate to the file (e.g. vt 0.500 1) and reference it in every single face (turn f 113//113 76//76 77//77 into f 113/1/113 76/1/76 77/1/77)

Upvotes: -1

melfar
melfar

Reputation: 360

Sharing a possible answer for those coming here from Google.

glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof( indices ), &indices[0], GL_STATIC_DRAW );

Note the copypaste error in bold. This caused error 1285 and quite a bit of head scratching for quite some time.

Upvotes: 2

Njol
Njol

Reputation: 3279

You should first verify that you make all OpenGL class in the correct order, e.g. you should only bind the VBOs when creating the VAO, not when rendering it.

Here's how I order the calls in my VAO class:

    // creation
    array = glGenVertexArrays();
    glBindVertexArray(array);

    vertices = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, vertices);
    glBufferData(GL_ARRAY_BUFFER, b, usage);

    for (attributes) {
        glEnableVertexAttribArray(index);
        glVertexAttribPointer(index, dimension, type, false, bytesPerVertex, offset);
    }

    if (indices are used) {
      indices = glGenBuffers();
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer, usage);
    }

    // render
    glBindVertexArray(array);
    program.use(); // binds shader program and textures
    if (indices == -1)
        glDrawArrays(mode, 0, size);
    else
        glDrawElements(mode, size, indicesType, 0);

Upvotes: 0

Related Questions