Intereting Posts

Android ICS SurfaceHolder.lockCanvas () не удалось внутренне и возвращает null

Я получил образец проекта BasicGLSurfaceView и изменил его, чтобы имитировать проблему, с которой мы сталкиваемся в нашем проекте.
Я изменил действие, чтобы использовать API-интерфейс luckCanvas для SurfaceHolder из GLSurfaceView:

public class BasicGLSurfaceViewActivity extends Activity implements OnClickListener { //Added a on click listener to draw some text on the view ...... @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); mView = new BasicGLSurfaceView(getApplication()); mView.setOnClickListener(this); // adding the on click listener setContentView(mView); } ............. @Override public void onClick(View arg0) { Toast.makeText(this, "OnClicked", Toast.LENGTH_SHORT).show();//Toast message AsyncTask asyncTask = new AsyncTask(){ @Override protected Void doInBackground(Void... params) { Canvas lockCanvas = mView.getHolder().lockCanvas(); // Trying to get canvas to draw something if(lockCanvas!=null){ Paint paint = new Paint(); paint.setColor(Color.RED); paint.setTextSize(36.0f); lockCanvas.drawText("Hello usgin locked canvas", 10, 50, paint); mView.getHolder().unlockCanvasAndPost(lockCanvas); } return null; } }; asyncTask.execute(); } } 

Если вы проверите этот код, вы увидите, что lockCanvas всегда имеет значение null, а внутри logcat отображается следующая ошибка:

01-02 00:29:39.260: E/SurfaceHolder(1245): java.lang.IllegalArgumentException 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.Surface.lockCanvasNative(Native Method) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.Surface.lockCanvas(Surface.java:76) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.SurfaceView$4.internalLockCanvas(SurfaceView.java:771) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.SurfaceView$4.lockCanvas(SurfaceView.java:747) 01-02 00:29:39.260: E/SurfaceHolder(1245): at com.example.android.basicglsurfaceview.BasicGLSurfaceViewActivity$1.doInBackground(BasicGLSurfaceViewActivity.java:61) 01-02 00:29:39.260: E/SurfaceHolder(1245): at com.example.android.basicglsurfaceview.BasicGLSurfaceViewActivity$1.doInBackground(BasicGLSurfaceViewActivity.java:1) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.os.AsyncTask$2.call(AsyncTask.java:264) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.lang.Thread.run(Thread.java:856)
01-02 00:29:39.260: E/SurfaceHolder(1245): java.lang.IllegalArgumentException 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.Surface.lockCanvasNative(Native Method) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.Surface.lockCanvas(Surface.java:76) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.SurfaceView$4.internalLockCanvas(SurfaceView.java:771) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.view.SurfaceView$4.lockCanvas(SurfaceView.java:747) 01-02 00:29:39.260: E/SurfaceHolder(1245): at com.example.android.basicglsurfaceview.BasicGLSurfaceViewActivity$1.doInBackground(BasicGLSurfaceViewActivity.java:61) 01-02 00:29:39.260: E/SurfaceHolder(1245): at com.example.android.basicglsurfaceview.BasicGLSurfaceViewActivity$1.doInBackground(BasicGLSurfaceViewActivity.java:1) 01-02 00:29:39.260: E/SurfaceHolder(1245): at android.os.AsyncTask$2.call(AsyncTask.java:264) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 01-02 00:29:39.260: E/SurfaceHolder(1245): at java.lang.Thread.run(Thread.java:856) 

Но этот код работает в GingerBread без каких-либо проблем.
Не могли бы вы объяснить, какие изменения в сэндвиче с мороженым вызывают эту проблему или что будет обходным путем для решения этой проблемы?

Кроме того, я получаю также следующую ошибку:

12-21 10:04:47.254: E/EglHelper(17382): eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=1507 12-21 10:04:47.285: E/AndroidRuntime(17382): FATAL EXCEPTION: GLThread 1507 12-21 10:04:47.285: E/AndroidRuntime(17382): java.lang.RuntimeException: eglSwapBuffers failed: EGL_BAD_SURFACE 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1178) 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1136) 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463) 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
12-21 10:04:47.254: E/EglHelper(17382): eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=1507 12-21 10:04:47.285: E/AndroidRuntime(17382): FATAL EXCEPTION: GLThread 1507 12-21 10:04:47.285: E/AndroidRuntime(17382): java.lang.RuntimeException: eglSwapBuffers failed: EGL_BAD_SURFACE 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1178) 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1136) 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463) 12-21 10:04:47.285: E/AndroidRuntime(17382): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216) 

Большое спасибо.