12

动态壁纸崩溃,代码如下

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):致命异常:线程 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): 在 com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)

提前致谢

4

1 回答 1

3

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

if (canvas != null) {
    try {
        holder.unlockCanvasAndPost(canvas);
    } catch (IllegalArgumentException e) {
        // Ignore weird bug when rotating in live wallpaper picker
    }
}
于 2013-04-08T08:22:41.203 回答