簡體   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