android opengl: createWindowSurface returned EGL_BAD_NATIVE_WINDOW.

来源:互联网 发布:麻辣it 编辑:程序博客网 时间:2024/06/03 17:43

我擦了,这个问题真是个老大难。

 

我使用的设备是一个三星的pad,2.2系统,型号忘了,反正是之前很流行的一个设备。

尼玛系统文档说好了2.2是支持opengl的呀,肿么就创建window失败呢,百思不得其解啊

 

折腾了两天呀,最后终于被我发现了苗头了。

我的代码这么写的(代码编译不过了,有些东西被我删了,您就别copy了)

 

public class MyGLSurface extends GLSurfaceView

private TCGLRender mMyGLRender;


 public MyGLSurface(Context context, AttributeSet attrs) {
  super(context, attrs);

  if (getGLVersion(context) == 2) {
   mIsSupportGLV2 = true;
  }

  if (mIsSupportGLV2) {
   this.setEGLContextClientVersion(2);
  }

  mMyGLRender = new TCGLRender(mIsSupportGLV2, mBufFreeSem);
  mMyGLRender.setContext(context);
  this.setRenderer(mMyGLRender);
  this.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
 }
 

 public void onPause() {
  super.onPause();
 }

 public void onResume() {
  super.onResume();
 }

 public void DrawFrame(byte[] ydatas, byte[] udatas, byte[] vdatas,
   int width, int height, int dstWidth, int dstHeight, float degree,
   boolean isFull)
 {

  mMyGLRender.CopyFrame2Render(ydatas, udatas, vdatas, width, height, dstWidth, dstHeight, degree, isFull);
  this.requestRender();
 }

 static public int getGLVersion(Context context) {
  ActivityManager am = (ActivityManager) context
    .getSystemService(Context.ACTIVITY_SERVICE);
  ConfigurationInfo info = am.getDeviceConfigurationInfo();
  return (info.reqGlEsVersion >= 0x00020000) ? 2 : 1;
 }
 
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
 {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  this.setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
 }

}

 

看到没有,红色的部分就是特么的罪魁祸首了,我揣测2.2系统里面GLSurfaceView里面没有这个方法,所以一直override之后就有问题了

 

把他删掉就OK了

类似的,可能类似的问题也呼导致这个 EGL_BAD_NATIVE_WINDOW的错误,大家出现的时候可以关注一下

 

OK,打完收工

 

 

 

原创粉丝点击