Hi All, I've been playing around with OpenGL ES on my phone and have hit a strange bug that looks like it may be caused by the GC problem discussed in this post. Basically I'm drawing a single quad (actually 2 triangles) in glOrtho and rotating it around the z-axis, but the app stutters every couple of seconds. After looking at DDMS log I get this:
09-02 15:21:28.892: DEBUG/dalvikvm(15501): GC freed 18 objects / 640 bytes in 221ms 09-02 15:21:29.712: DEBUG/dalvikvm(31045): GC freed 13470 objects / 524240 bytes in 140ms 09-02 15:21:31.152: DEBUG/dalvikvm(31045): GC freed 13466 objects / 524248 bytes in 136ms 09-02 15:21:32.602: DEBUG/dalvikvm(31045): GC freed 13471 objects / 524328 bytes in 145ms 09-02 15:21:34.052: DEBUG/dalvikvm(31045): GC freed 13464 objects / 524208 bytes in 152ms 09-02 15:21:35.492: DEBUG/dalvikvm(31045): GC freed 13467 objects / 524272 bytes in 133ms 09-02 15:21:36.952: DEBUG/dalvikvm(31045): GC freed 13468 objects / 524360 bytes in 144ms 09-02 15:21:38.382: DEBUG/dalvikvm(31045): GC freed 13466 objects / 524200 bytes in 136ms 09-02 15:21:39.832: DEBUG/dalvikvm(31045): GC freed 13471 objects / 524344 bytes in 138ms 09-02 15:21:41.272: DEBUG/dalvikvm(31045): GC freed 13467 objects / 524224 bytes in 135ms 09-02 15:21:42.722: DEBUG/dalvikvm(31045): GC freed 13470 objects / 524312 bytes in 142ms etc... The stutters seem to match up with the GC. However, I tried Dmitry's non-direct ByteBuffer code in the hope that it would calm the GC down, but it has no effect! I find it hard to believe that my app is creating 13k object every 140ms! What do you think, is this the dreaded Android OpenGL garbage leak? Many thanks. On Aug 5, 7:09 am, "Dmitry.Skiba" <[email protected]> wrote: > Good news, gyus! > > I've found a way to get rid of garbage collection! > The receipt is simple (and ironic): do not use allocateDirect(), use > allocate(). And use only ByteBuffer, not FloatBuffer, IntBuffer, etc. > - using asFloatBuffer() on non-direct ByteBuffer will result in crash > in libhgl. (I'm too lazy to create an issue for that.) > > E.g. this code: > > ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); > vbb.order(ByteOrder.nativeOrder()); > mVertexBuffer = vbb.asIntBuffer(); > mVertexBuffer.put(vertices); > mVertexBuffer.position(0); > > should be > > ByteBuffer vbb = ByteBuffer.allocate(vertices.length*4); > vbb.order(ByteOrder.nativeOrder()); > for (int vertex: vertices) { > mVertexBuffer.putInt(vertex); > } > mVertexBuffer.position(0); > > and voila, no garbage collections on ADP 1.5 firmware. > > Please test and report your results here. > > Dmitry > > On 16 июл, 21:33, PaulT <[email protected]> > wrote: > > > Hello everybody, > > > I've created a simple OpenGL app and created a rendering class which > > implements GLSurfaceView.Renderer. All it does is draw 100 triangles > > (NUM_OBJECTS = 100) on the screen and move them about, bouncing off > > the edges. The projection is glOrtho2D and there is no z-buffer. I'm > > running this on a G1 with continuous redraw enabled. > > > Here is the onDrawFrame method: > > > public void onDrawFrame(GL10 gl) { > > gl.glClear(GL10.GL_COLOR_BUFFER_BIT); > > for (n = 0; n < NUM_OBJECTS; n++) { > > gl.glPushMatrix(); > > gl.glTranslatef(posX[n], posY[n], 0); > > gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vBuffer); > > gl.glDrawElements(GL10.GL_TRIANGLES, 3, GL10.GL_UNSIGNED_SHORT, > > iBuffer); > > gl.glPopMatrix(); > > posX[n] += xa[n]; > > posY[n] += ya[n]; > > if (posX[n] > viewW || posX[n] < 0) { > > xa[n] = -xa[n]; > > } > > if (posY[n] > viewH || posY[n] < 0) { > > ya[n] = -ya[n]; > > } > > } > > > } > > > It's pretty simple stuff just to get an idea of the device > > performance. Note that I am not leaking any garbage in this method. > > > If we look at the logs while this is running, > > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 153ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 156ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 157ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 156ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 156ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 157ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 152ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 150ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 153ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 157ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 151ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 159ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 155ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 156ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 153ms > > D/dalvikvm( 3085):GCfreed 21842 objects / 524304 bytes in 158ms > > D/dalvikvm( 3085):GCfreed 21840 objects / 524256 bytes in 151ms > > > Every few seconds, the garbage collector has a bit of a tidy up. If > > we look at the frame rate, it is averaging out to be around 56Hz. I > > speculate that the system can keep up with the 60Hz vertical sync just > > fine until it needs to collect garbage. > > > Nothing else is running so this stuff is definitely coming from this > > app. Unfortunately it causes the display to pause briefly (160ms is > > about 10 frames) so would not be acceptable in an interactive game. > > Does anybody know what causes this (something in the OpenGL code?) and > > can it be avoided? > > > Thanks for any help. > > > Paul. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

