GL_OUT_OF_MEMORY after a call to glDrawArrays. Why?
Asked Answered
L

5

6

I have a situation that seems rather strange. I will try to provide enough details, so that someone smarter than me can explain this. Basically here is the setup:

OS: Android 2.2 Froyo
Device: SGS Vibrant
Application: OpenGL-ES 1.1

And here is the problem: I can successfully render a fairly complex scene, and it can run endlessly for hours without leaking any memory. Dalvikvm shows up in the logcat once every 3-5 minutes and there would have been no problem unless I try to exit my application and run it again. In fact I can restart my application 2 times, but on the third time, I get GL_OUT_OF_MEMORY.

I have tracked the error down to the gl.glDrawArrays() call. I can confirm that the gl.glGetError() returns 0 prior to the DrawArrays call in question, and it will return 1285 (GL_OUT_OF_MEMORY) after the DrawArrays call.

Naturally, I have thought that I am not cleaning up the resources and releasing OpenGL context. Here is what I do when the application is being shut down.

for(int x=0; x<buffers.length; x++){
   if(gl.glIsBuffer(buffers[x])){
      gl.glDeleteBuffers(1, buffers, x);
      buffers[x]=0;
   }
}
for(int y=0; y<textures.length; y++){
   if(gl.glIsTexture(textures[y])){
      gl.glDeleteTextures(1, textures, y);
      textures[y]=0;
   }
}
System.out.println("ERROR: "+gl.glGetError());
finish();

When I run my application the first two times, I do not get any error returned at shutdown. However on the 3rd try, I get the aforementioned error, which I tracked down to the gl.glDrawArrays() call.

Here is a brief summary of what happens during the 3rd run:

  1. Objects 1-56 go through their respective gl.glDrawArrays() calls like hot knives through butter. No errors generated.

  2. Objects 57-64 generate a GL_OUT_OF_MEMORY error. The objects get rendered, but the texture is black.

I am more than sure that I am deleting all of the Buffers and Textures at app shutdown. I am also confident that this error is not specific to one 3D model, as I have tried skipping model #57, but then #58 will still get this error.

Please help, as I am running out of ideas!

Leonorleonora answered 9/6, 2011 at 2:42 Comment(0)
S
8

I just found out GL_OUT_OF_MEMORY can be set if you first pass the NULL pointer to glVertexAttribPointer.

No error before drawArrays, GL_OUT_OF_MEMORY after. (tested on Galaxy S2 4.1.2, GLES2) Maybe that's what's going on for some reason after a while in your program?

this took me forever to find... TODO: more unit tests :)

Secondly answered 30/4, 2013 at 12:52 Comment(0)
P
2

GL_OUT_OF_MEMORY after a call to glDrawArrays. Why?

It is really hard to say but from what I have learned, this error occurs when you are having too many polygons in memory, or at least, same vertices are being defined n times. Since you said you're having a complex scene; this problem is probably a memory problem.

One solution could be to use glDrawElements() and let your scene reduce the amount of vertices by letting your polygons share same vertices when necessary. In this way your memory is lowered and it is possible that this fixes the problem.

Plumlee answered 10/7, 2011 at 21:42 Comment(0)
S
2

I found that glDrawArrays() was setting GL_OUT_OF_MEMORY when glVertexAttribPointer() was being called with a non-null pointer. This turned out to be because a different bit of code had called glBindBuffer() to use a vertex array object but then hadn't unbound the buffer afterwards. A call to glBindBuffer(GL_ARRAY_BUFFER, 0) fixed the problem.

Sanfo answered 27/1, 2014 at 14:32 Comment(0)
L
1

Can also happen if you have incorrect glVertexAttribPointer calls on Android. I got this error , when I incorrectly passed ST attributes to a previously prepared normal attribute (duplicate glVertexAttribPointer calls to prepare the normal attribute, the second should have bound to the ST attribute).

Legionary answered 27/8, 2013 at 21:19 Comment(0)
T
0

In my case, this GL_OUT_OF_MEMORY error was also thrown after glDrawArrays, because my framebuffer had an attachment texture that didn't have any memory allocated on GPU (in particular I called glTexStorage2D with levels equal to 0).

My setup is mobile:

  • OpenGL ES 3.2
  • Qualcomm Snapdragon 888
  • Harmony OS v4.0
Tartarus answered 29/1 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.