首页 > 代码库 > OpenGL,Android注意事项初始化顺序 NullPointer

OpenGL,Android注意事项初始化顺序 NullPointer

BUG:

Caused by: java.lang.IllegalStateException: setRenderer has already been called for this instance.

或者NullPointer错误


解决方法:

把setEGLContextClientVersion(2);挪到setRenderer()前面。方法的注释上写到“If this method is called, it must be called beforesetRenderer(Renderer) is called. 
”。


拓展:

并且setRender()之后之前的方法调用顺序,也是固定。详情可以看代码注释,如下:

This method should be called once and only once in the life-cycle of a GLSurfaceView.

(这些方法只能在CLSurfaceView中有且只能调用一次)

The following GLSurfaceView methods can only be called before setRenderer is called:

(setRender前调用,当然也包括setEGLContextClientVersion(2))

  • setEGLConfigChooser(boolean)
  • setEGLConfigChooser(EGLConfigChooser)
  • setEGLConfigChooser(int, int, int, int, int, int)

The following GLSurfaceView methods can only be called after setRenderer is called:

(setRender后调用)

  • getRenderMode()
  • onPause()
  • onResume()
  • queueEvent(Runnable)
  • requestRender()
  • setRenderMode(int)

OpenGL,Android注意事项初始化顺序 NullPointer