Android ICS SurfaceHolder.lockCanvas() failed internally and return null
<p>I got the sample project BasicGLSurfaceView and modified to simulate a issue which we are facing in our project.
I modified Activity to use the luckCanvas API of SurfaceHolder of GLSurfaceView:</p>

<pre>
<code>
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();

    }
}

</code>
</pre>

<p>if you check this code the lockCanvas always null and following error shown in side logcat:</p>

<pre>
<code>
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)
</code>
</pre>

<p>But this code workng in GB without any issues. Could you please explain what changes in ICS cases this issue or what would be the work around to resolve this issues?</p>

<p>Additionally I am getting following error also:</p>

<pre>
<code>
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)

</code>
</pre>

<p>Thanks a lot.</p>
