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:
Objects 1-56 go through their respective gl.glDrawArrays()
calls like hot knives through butter. No errors generated.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With