开发者

GL_OUT_OF_MEMORY after a call to glDrawArrays. Why?

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 g开发者_开发技巧et 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!


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 :)


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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜