- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 Samsung Galaxy S6 上安装后第一次打开应用程序时出现 eglCreateWindowSurface GL Error EGL_BAD_ALLOC
并且相同的代码在其他设备上工作正常。
我试图清理内存并销毁纹理并在销毁时取消初始化所有 opengl 对象,但这对我没有帮助。
03-30 09:21:32.983 21942-26083/com.example E/TextureSurfaceRenderer: createContext: EGL10.EGL_YES_CONTEXT com.google.android.gles_jni.GLImpl@24406d0
03-30 09:21:32.983 21942-26083/com.example E/libEGL: eglCreateWindowSurface: native_window_api_connect (win=0x7f7b100e10) failed (0xffffffea) (already connected to another API?)
03-30 09:21:32.983 21942-26083/com.example E/libEGL: eglCreateWindowSurface:485 error 3003 (EGL_BAD_ALLOC)
03-30 09:21:32.993 21942-26083/com.example E/GL Error:: EGL_BAD_ALLOC
这是我的代码。
import android.graphics.SurfaceTexture;
import android.opengl.GLUtils;
import android.os.Handler;
import android.util.Log;
import javax.microedition.khronos.egl.*;
/**
* Renderer which initializes OpenGL 2.0 context on a passed surface and starts
* a rendering thread
*
* This class has to be subclassed to be used properly
*/
public abstract class TextureSurfaceRenderer implements Runnable {
private static final int EGL_OPENGL_ES2_BIT = 4;
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
private static final String TAG = TextureSurfaceRenderer.class.getSimpleName();
protected final SurfaceTexture texture;
protected Handler myHandler;
private EGL10 egl;
private EGLDisplay eglDisplay;
private EGLContext eglContext;
private EGLSurface eglSurface;
protected int width;
protected int height;
private boolean running;
/**
* @param texture
* Surface texture on which to render. This has to be called
* AFTER the texture became available
* @param width
* Width of the passed surface
* @param height
* Height of the passed surface
*/
public TextureSurfaceRenderer(SurfaceTexture texture, int width, int height,Handler myHandler) {
this.myHandler = myHandler;
this.texture = texture;
this.width = width;
this.height = height;
this.running = true;
Thread thrd = new Thread(this);
thrd.start();
}
@Override
public void run() {
initGL();
if(eglSurface != null){
initGLComponents();
Log.d(TAG, "OpenGL init OK.");
while (running) {
long loopStart = System.currentTimeMillis();
pingFps();
boolean isDraw = draw();
// Log.e(TAG, "eglSwapBuffers Before Draw " + isDraw);
if (isDraw) {
if(!egl.eglSwapBuffers(eglDisplay, eglSurface)){
int error = egl.eglGetError();
Log.e(TAG, "eglSwapBuffers Error " + GLUtils.getEGLErrorString(error));
}
}
// Targeting 60 fps, no need for faster
long waitDelta = 16 - (System.currentTimeMillis() - loopStart);
if (waitDelta > 0) {
try {
Thread.sleep(waitDelta);
} catch (InterruptedException e) {
MyApplication.getInstance().trackException(e);
continue;
}
}
}
deInitGLComponents();
deinitGL();
} else {
Log.e(TAG, "Egl Surface is null " + GLUtils.getEGLErrorString(egl.eglGetError()));
}
}
/**
* Main draw function, subclass this and add custom drawing code here. The
* rendering thread will attempt to limit FPS to 60 to keep CPU usage low.
*/
protected abstract boolean draw();
/**
* OpenGL component initialization funcion. This is called after OpenGL
* context has been initialized on the rendering thread. Subclass this and
* initialize shaders / textures / other GL related components here.
*/
public abstract void initGLComponents();
public abstract void deInitGLComponents();
private long lastFpsOutput = 0;
private int frames;
private void pingFps() {
if (lastFpsOutput == 0)
lastFpsOutput = System.currentTimeMillis();
frames++;
if (System.currentTimeMillis() - lastFpsOutput > 1000) {
Log.d(TAG, "FPS: " + frames);
lastFpsOutput = System.currentTimeMillis();
frames = 0;
}
}
/**
* Call when activity pauses. This stops the rendering thread and
* deinitializes OpenGL.
*/
public void onPause() {
running = false;
}
private void initGL() {
egl = (EGL10) EGLContext.getEGL();
eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
egl.eglInitialize(eglDisplay, version);
EGLConfig eglConfig = chooseEglConfig();
eglContext = createContext(egl, eglDisplay, eglConfig);
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture,
null); // Here I am getting null eglSurface first Time.
if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
myHandler.sendEmptyMessage(0);
Log.e("GL Error: "
,""+ GLUtils.getEGLErrorString(egl.eglGetError()));
return;
}
if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
myHandler.sendEmptyMessage(0);
Log.e("GL Make current error: "
, "" + GLUtils.getEGLErrorString(egl.eglGetError()));
return;
}
}
private void deinitGL() {
egl.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
egl.eglDestroySurface(eglDisplay, eglSurface);
egl.eglDestroyContext(eglDisplay, eglContext);
egl.eglTerminate(eglDisplay);
Log.d(TAG, "OpenGL deinit OK.");
}
private EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay,
EGLConfig eglConfig) {
int[] attribList = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
EGLContext eglContext = egl.eglCreateContext(eglDisplay, eglConfig,
EGL10.EGL_NO_CONTEXT, attribList);
if(eglContext.getGL().equals(EGL10.EGL_NO_CONTEXT)){
Log.e(TAG, "createContext: EGL10.EGL_NO_CONTEXT");
} else {
Log.e(TAG, "createContext: EGL10.EGL_YES_CONTEXT " + eglContext.getGL().toString());
}
return eglContext;
}
private EGLConfig chooseEglConfig() {
int[] configsCount = new int[1];
EGLConfig[] configs = new EGLConfig[1];
int[] configSpec = getConfig();
if (!egl.eglChooseConfig(eglDisplay, configSpec, configs, 1,
configsCount)) {
Log.e(TAG , "Failed to choose config: " + GLUtils.getEGLErrorString(egl.eglGetError()));
} else if (configsCount[0] > 0) {
return configs[0];
}
return null;
}
private int[] getConfig() {
return new int[] { EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 0, EGL10.EGL_STENCIL_SIZE, 0, EGL10.EGL_NONE };
}
@Override
protected void finalize() throws Throwable {
super.finalize();
running = false;
}
}
最佳答案
所以你的 Activity 的
onPause()
应该是这样的:
@Override
public void onPause() {
eglSurface.setVisibility(View.GONE);
super.onPause();
...
}
并且您将 GLSurfaceView
恢复到层次结构不是来自 onResume()
而是来自 onWindowFocusChanged()
:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus && eglSurface.getVisibility() == View.GONE) {
eglSurface.setVisibility(View.VISIBLE);
}
...
}
另见:
eglCreateWindowSurface: native_window_api_connect failed
fixing-common-android-lifecycle-issues
关于android - Opengls eglCreateWindowSurface GL 错误 EGL_BAD_ALLOC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36312209/
我正在使用 Visual Studio 2010。 我正在尝试在 OpenGL 中编写简单的 Camera 类。 我需要在 Camera.h 中包含 gl/gl.h gl/gl.h 已经包含在 mai
这个问题适用于了解 MapBox GL JS 内部结构的人。 我正在使用 MapBox GL JS 渲染多达 40,000 个多边形的地理 map ,每个多边形的颜色都基于该多边形的“所有者”。每个所
我想知道3D建筑物的“填充颜色”是否可以根据某些事件动态更改,例如将鼠标悬停在建筑物上时的mouseMoveEvent,突出显示3D建筑物。 最佳答案 试试这个 map.on('load', func
我正在使用 mapbox-gl 并从 osm2vectortiles.org 下载矢量切片 我想让 map 仅在已知多边形内可见,但找不到任何方法来实现这一点。 我可以想象几种解决这个问题的方法,但每
在探索javascript的过程中,我遇到了一个很莫名其妙的问题。序言是:我将不同 mime 类型的图像(主要是 pngs/jpgs)转换为具有 ImageBitmap 接口(interface)的位
我一直在使用行程图层可视化行程数据,并且尝试在每条行程线的开头放置一个图标。是否可以让多个图标随时间改变位置、出现和消失? Example of what I'm trying to do (red
我有一个 map 应用程序,它使用 Mapbox.com 来提供英国邮政编码边界的矢量切片。边界文件很大,不适合使用 TopoJSON 之类的工具进行下载。这很好用。 我还使用数据驱动的样式来格式化
将鼠标悬停在一个 3D 建筑上时,如何突出显示它?像 OSM 建筑物突出显示功能。 mapbox street v7 建筑图层特征属性好像很少,只包括: 拉伸(stretch) 高度 最小高度 类型
有没有办法隐藏/删除或禁用控件,例如 mapbox-gl-draw 中的控件? 我添加绘制控件如下 draw = mapboxgl.Draw({ drawing: true,
这可能非常简单,但我找不到如何在 deck.gl 的标签下方添加新层。它在底层使用 Mapbox GL JS。对于 mapbox gl,解释为 here . 我还在他们的文档中搜索了 z-index
我正在寻找一种方法,允许我像 Mapbox JS 一样为我的 map 创建一个简单的自定义标记。 深入浏览了网络,似乎没有明显或非常直接的方法来实现这一目标。我猜这是一个被错过的功能。 尝试过使用Ma
接下来的教程向我展示了以下代码: ... void update() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES);
我正在寻找一种方法,允许我像 Mapbox JS 一样为我的 map 创建一个简单的自定义标记。 深入浏览了网络,似乎没有明显或非常直接的方法来实现这一目标。我猜这是一个被错过的功能。 尝试过使用Ma
我想在交互式 map 上显示一个圆圈的轮廓(无填充)但是,mapbox-gl-js 中的绘制选项似乎仅限于填充。 https://www.mapbox.com/mapbox-gl-style-spec
我在 kepler.gl 中工作并从数据库加载数据。如果数据库更新,我希望能够动态更新数据集。有没有办法向数据集添加一行并更新 map ? 我已经尝试删除数据集(使用 removeDataset)并将
如何在 mapbox-gl 中为图层文本字段添加背景颜色 .. 或者如何完成以便文本字段上有背景框 map.addLayer({ "id": "markers", "type": "s
我正在尝试使用 mapbox-gl 创建等值线图。在示例等值线 map 中,看起来他们根据要素的属性设置了要素的油漆填充颜色。有没有办法通过访问 map 来设置颜色? 即。我在称为 id 的功能属性中
我想根据最近的草皮更改 map 点击时的图标大小。我如何做到这一点? nearestBuilding.properties['icon-size'] = 0.2; 不起作用。 var retail =
我正在尝试在 MapBox GL JS 中聚类自定义标记,但我不知道如何将自定义标记图像从 url 获取到符号层?它要么不起作用,要么根本没有标记出现。它是如何完成的?我需要知道如何使用带有符号层的
寻找一种使用 Mapbox GL JS 获取 map 中心当前坐标的方法,就像在 Mapbox Studio 上一样(见下文) Mapbox Studio Screenshot 谢谢 最佳答案 Map
我是一名优秀的程序员,十分优秀!