壁纸崩溃错误 - queueBuffer:错误排队缓冲区到SurfaceTexture

时间:2012-06-07 19:19:40

标签: android canvas live-wallpaper surfaceholder


动态壁纸崩溃,代码

public void render(){


    Canvas canvas = null;
    try{

        canvas = this._surfaceHolder.lockCanvas(null);
        synchronized (this._surfaceHolder) {
            this.onDraw(canvas);
        }

    }catch(Exception e){ Log.w("Surface holder ", e.toString());}

    finally{
        if(canvas != null){
            this._surfaceHolder.unlockCanvasAndPost(canvas);
        }
    }   
}

protected void onDraw(Canvas canvas) {
    this.renderBackGround(canvas);
    for (Renderable renderable : this._fishes) {
        renderable.render(canvas);
    }
};

发生以下错误

崩溃

06-07 19:49:09.143:E / SurfaceTextureClient(13629):queueBuffer:错误排队缓冲区到SurfaceTexture,-19

06-07 19:49:09.143:E / SurfaceTextureClient(13629): queueBuffer(handle = 0x1c1b30)失败(没有这样的设备) 06-07 19:49:09.143:W / dalvikvm(13629):threadid = 11:线程退出未捕获异常(组= 0x40c671f8) 06-07 19:49:09.143:E / AndroidRuntime(13629): 致命异常:Thread-692

06-07 19:49:09.143:E / AndroidRuntime(13629):java.lang.IllegalArgumentException

06-07 19:49:09.143:E / AndroidRuntime(13629):在android.view.Surface.unlockCanvasAndPost(原生方法)

06-07 19:49:09.143:E / AndroidRuntime(13629):at com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)

提前致谢

1 个答案:

答案 0 :(得分:3)

当您在动态壁纸选择器中旋转设备时,通常会发生这种情况。我发现的唯一解决方案是捕获IllegalArgumentException并忽略它。

if (canvas != null) {
    try {
        holder.unlockCanvasAndPost(canvas);
    } catch (IllegalArgumentException e) {
        // Ignore weird bug when rotating in live wallpaper picker
    }
}