我使用openGL创建了android动态壁纸.Wallpaper运行不到一分钟,并显示加载动态壁纸但是当点击设置选项它运行一段时间并在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);
}
答案 0 :(得分:0)
您不断创建新的纹理对象,并在绘图函数的每次迭代中填充它们。这不仅效率低(纹理应加载一次然后重复使用),而且还会导致内存泄漏,因为OpenGL内部纹理对象不会被垃圾回收。