0

我正在構建一個動態壁紙,它具有全高清分辨率的位圖,並縮小到用戶手機屏幕的大小。它在Android 2.2和2.3上完美運行,但在4.0上崩潰。SurfaceView:dequeueBuffer在Android 4.0上失敗

編輯:

我縮小了問題下使用的try/catch一點點,發現它從我的run()方法開始。與馬蓋先修復它運行約20秒驅下面的錯誤消息,然後崩潰:

05-31 20:01:22.590: E/SurfaceTextureClient(1475): dequeueBuffer failed (No such device) 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): Exception locking surface 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): java.lang.IllegalArgumentException 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): at android.view.Surface.lockCanvasNative(Native Method) 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): at android.view.Surface.lockCanvas(Surface.java:76) 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): at com.android.internal.view.BaseSurfaceHolder.internalLockCanvas(BaseSurfaceHolder.java:184) 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): at com.android.internal.view.BaseSurfaceHolder.lockCanvas(BaseSurfaceHolder.java:157) 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): at com.pelkkala.test.TestWall$TestMachine.run(TestWall.java:255) 
05-31 20:01:22.590: E/BaseSurfaceHolder(1475): at java.lang.Thread.run(Thread.java:856) 
05-31 20:01:22.601: E/ERROR(1475): ERROR IN CODE: java.lang.NullPointerException 
05-31 20:01:22.621: W/System.err(1475): java.lang.NullPointerException 
05-31 20:01:22.621: W/System.err(1475):  at com.pelkkala.test.TestWall$TestMachine.draw(TestWall.java:233) 
05-31 20:01:22.636: W/System.err(1475):  at com.pelkkala.test.TestWall$TestMachine.run(TestWall.java:264) 
05-31 20:01:22.636: W/System.err(1475):  at java.lang.Thread.run(Thread.java:856) 

這是我的run()方法:

 public void run() { 

     while (running) { 
      //perform canvas drawing 
      if (!holder.getSurface().isValid()) { 
       continue; 
      } 

      mTimer = System.currentTimeMillis(); 

      if (mTimer - oldTime > 50) { 
       oldTime = mTimer; 
       try { 
        Canvas c = holder.lockCanvas(); 

        if (!touching) { 
         oscillate(xOrig, yOrig); 
        } 
        if (!touching2) { 
         oscillate2(xOrig2, yOrig2); 
        } 

        draw(c);   
        holder.unlockCanvasAndPost(c); 
       } 
       catch (Exception e) { 
        Log.e("ERROR", "ERROR IN CODE: " + e.toString()); 
        e.printStackTrace(); 
       } 
      } 
     } 
    } 

編輯2:

莫非它與模擬器有關係嗎?我現在無法訪問Android 4設備,所以這就是我所擁有的。

回答

0

我還不確定爲什麼會發生這種情況與Android 4,但這是我如何解決它。

這是造成我的麻煩:

class TestEngine extends Engine implements Runnable {} 


所以我改成了這樣的事情:

class TestEngine extend Engine { 

    private final Runnable testRunnable = new Runnable() { 
     public void run() { 
      drawFrame(); 
     } 
    }; 

    public void drawFrame() { 

     //Draw on canvas and unlock 
     ... 
     mHandler.postDelayed(testRunnable, 1000/50); 
    } 
}