繁体   English   中英

GC_FOR_ALLOC发行了动态壁纸

[英]GC_FOR_ALLOC freed issue live wallpaper

我使用openGL创建了android动态壁纸。壁纸运行不到一分钟,并显示正在加载动态壁纸,但是当单击“设置”选项时,它将运行一段时间并在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

当墙纸正在运行时,logcat显示,

         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

我的onDrawFrame方法是

        @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);


  }

您将不断创建新的纹理对象,并在每次绘制函数迭代时填充它们。 这不仅效率低下(纹理应该加载一次然后再使用),而且还因为OpenGL内部纹理对象没有被垃圾回收而导致内存泄漏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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