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!