- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试用 EGL 初始化 GLES(因为我想从主线程中绘制而不是使用渲染器并从 onDrawFrame 内部绘图)。我收到错误消息:“确保 SurfaceView 或关联的 SurfaceHolder 具有有效的 Surface”。显然 mEgl.eglCreateWindowSurface 失败了,因为 surfaceHolder 没有有效的表面。如何获得具有有效 Surface 的 SurfaceHolder 才能继续?
我的 Activity.onCreate 方法是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GLSurfaceView surfaceView = new GLSurfaceView(this);
setContentView(surfaceView);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
Surface surface = surfaceHolder.getSurface();
Log.v("HelloAndroid", "surface.isValid()= " + Boolean.toString(surface.isValid()));
EGL10 mEgl = (EGL10) EGLContext.getEGL();
EGLDisplay mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
mEgl.eglInitialize(mEglDisplay, version);
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
int[] configSpec = {
EGL10.EGL_NONE
};
mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);
EGLConfig mEglConfig = configs[0];
EGLContext mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig,
EGL10.EGL_NO_CONTEXT, null);
EGLSurface mEglSurface = null;
Log.v("HelloAndroid", "M");
mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay,
mEglConfig, surfaceHolder, null);
Log.v("HelloAndroid", "N");
mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
mEglContext);
Log.v("HelloAndroid", "O");
}
我使用 platform-tools/adb logcat 得到的日志输出是:
V/HelloAndroid( 1861): surface.isValid()= false
D/libEGL ( 1861): egl.cfg not found, using default config
D/libEGL ( 1861): loaded /system/lib/egl/libGLES_android.so
V/HelloAndroid( 1861): M
D/AndroidRuntime( 1861): Shutting down VM
W/dalvikvm( 1861): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 1861): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 1861): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.HelloAndroid}: java.lang.IllegalArgumentException: Make sure the SurfaceView or associated SurfaceHolder has a valid Surface
E/AndroidRuntime( 1861): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
感谢任何帮助。
最佳答案
surface
的有效性检查应该在创建 surface 时进行。所以,surface.isValid()
应该在onSurfaceCreated
或onSurfaceChanged
中调用,显然,你应该添加surfaceholder.callback
.
关于android - 如何获得具有有效 Surface 的 SurfaceHolder(EGL.eglCreateWindowSurface 需要)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5577256/
当 android:hardwareAccelerated 设置为 false 到 list 文件中时,我只有最新的 Samsung Galaxy 系列才会出现问题 据我所知(我自己尝试过)它发生在
在 Samsung Galaxy S6 上安装后第一次打开应用程序时出现 eglCreateWindowSurface GL Error EGL_BAD_ALLOC 并且相同的代码在其他设备上工作正常
在使用 GLSurfaceView 启动某些 Activity 期间尝试快速按下后退按钮时, eglCreateWindowSurface失败 java.lang.IllegalArgumentExc
我有一个有趣的事件,一个应用程序正在开发中,在 Android 的原生 NDK C++ 上使用 OpenGL ES。程序编译运行没有问题。但是,如果我决定进行单元测试并调试代码,它会报错并显示以下消息
我正在尝试让基于 NDK 的游戏在 Android ICS 上运行。它在 Honeycomb 和 Gingerbread 上运行良好。 游戏使用一些 2D 渲染,一些 3D 渲染,在执行的不同阶段在两
我尝试用 EGL 初始化 GLES(因为我想从主线程中绘制而不是使用渲染器并从 onDrawFrame 内部绘图)。我收到错误消息:“确保 SurfaceView 或关联的 SurfaceHolder
我是一名优秀的程序员,十分优秀!