简体   繁体   中英

GC_FOR_ALLOC freed issue live wallpaper

I have created android live wallpaper using openGL.Wallpaper runs less than one minute and shows loading live wallpaper but when clicking Settings option It runs for some time and give the following in logcat,

          06-27 21:06:35.057: W/Adreno-EGLSUB(14285): <DequeueBuffer:591>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
          06-27 21:06:35.057: W/Adreno-ES20(14285): <gl2_surface_swap:43>: GL_OUT_OF_MEMORY
          06-27 21:06:35.057: W/Adreno-EGL(14285): <qeglDrvAPI_eglSwapBuffers:3595>: EGL_BAD_SURFACE
          06-27 21:06:35.127: W/Adreno-EGLSUB(14285): <DequeueBuffer:591>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
          06-27 21:06:35.127: W/Adreno-ES20(14285): <gl2_surface_swap:43>: GL_OUT_OF_MEMORY
         06-27 21:06:35.127: W/Adreno-EGL(14285): <qeglDrvAPI_eglSwapBuffers:3595>: EGL_BAD_SURFACE
         06-27 21:06:35.137: E/Surface(14285): queueBuffer: error queuing buffer to SurfaceTexture, -19
         06-27 21:06:35.137: W/Adreno-EGLSUB(14285): <SwapBuffers:1328>: failed to queueBuffer
         06-27 21:06:35.137: W/Adreno-EGL(14285): <qeglDrvAPI_eglSwapBuffers:3652>: EGL_BAD_SURFACE
         06-27 21:06:35.178: W/Adreno-EGLSUB(14285): <DequeueBuffer:591>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
         06-27 21:06:35.178: W/Adreno-ES20(14285): <gl2_surface_swap:43>: GL_OUT_OF_MEMORY
         06-27 21:06:35.178: W/Adreno-EGL(14285): <qeglDrvAPI_eglSwapBuffers:3595>: EGL_BAD_SURFACE
         06-27 21:06:35.188: E/Surface(14285): queueBuffer: error queuing buffer to SurfaceTexture, -19
         06-27 21:06:35.188: W/Adreno-EGLSUB(14285): <SwapBuffers:1328>: failed to queueBuffer
         06-27 21:06:35.188: W/Adreno-EGL(14285): <qeglDrvAPI_eglSwapBuffers:3652>: EGL_BAD_SURFACE

when wallpaper is running logcat shows,

         06-27 21:06:11.923: D/-heap(14285): GC_FOR_ALLOC freed 1955K, 68% free 3710K/11376K, paused 15ms, total 15ms
         06-27 21:06:12.083: D/-heap(14285): GC_FOR_ALLOC freed 1955K, 68% free 3710K/11376K, paused 16ms, total 16ms

and my onDrawFrame method is,

        @Override
  public void onDrawFrame(final GL10 gl) {
     try{
         square.draw(gl);
         }catch(Exception e){
             e.printStackTrace();
        }
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, 0.0f, -5.0f); 
     String strSavedurl = prefs.getString("rotspeed", "20");
      //  System.out.println("new try"+strSavedurl);
       String planetname = prefs.getString("planetselect", "");
       // System.out.println("new try"+planetname);
        planet_number=Integer.parseInt(planetname);
        if(planet_number==0){
              try{
            this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.mercury);
              }catch(Exception e){
              e.printStackTrace();
          }
            }
        else if(planet_number==1){
              try{
            this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.venus);
              }catch(Exception e){
              e.printStackTrace();
          }
            }
            else if(planet_number==2){
                  try{
                        this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.earth);
                          }catch(Exception e){
                          e.printStackTrace();
                      } 
            }
              else if(planet_number==3){
                  try{
                this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.mars);
                  }catch(Exception e){
                  e.printStackTrace();
              }
                }
                else if(planet_number==4){
                      try{
                            this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.jupiter);
                              }catch(Exception e){
                              e.printStackTrace();
                          } 
                }
                  else if(planet_number==5){
                      try{
                    this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.saturn);
                      }catch(Exception e){
                      e.printStackTrace();
                  }
                    }
                    else if(planet_number==6){
                          try{
                                this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.uranus);
                                  }catch(Exception e){
                                  e.printStackTrace();
                              } 
                    }
                    else if(planet_number==7){
                          try{
                                this.mEarth.loadGLTexture(gl, this.mContext,R.drawable.neptune);
                                  }catch(Exception e){
                                  e.printStackTrace();
                              } 
                    }

      Float stod;

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glPushMatrix();
     gl.glTranslatef(0, 0, -3.0f); 
     gl.glDepthMask(false);
    // gl.glRotatef(mAngleX, 0, 1, 0);
    // gl.glRotatef(mAngleY, 1, 0, 0);
     try{
     square.draw(gl);
     }catch(Exception e){
         e.printStackTrace();
    }
     gl.glPopMatrix();
    // gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     gl.glLoadIdentity();
     gl.glDepthMask(true);
    gl.glTranslatef(0.0f, 0.0f, OBJECT_DISTANCE);
    gl.glRotatef(AXIAL_TILT_DEGRESS, 1, 0, 0);
    gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); // X
    gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); // Y

    gl.glRotatef(this.mRotationAngle++, 0, 1, 0);
    try{
    this.mEarth.draw(gl);
    }catch(Exception e){
         e.printStackTrace();
    }
  //  stod=(float) 10.0;
    stod=Float.valueOf(strSavedurl);
    mRotationAngle=(float) (mRotationAngle+stod);


  }

You're constantly creating new texture objects and filling them with each iteration of your drawing function. Not only is this inefficient (textures should be load one time and then reused) but also it causes a memory leak because OpenGL internal texture objects are not garbage collected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM