android-eglCreateWindowSurface:native_window_api_connect失败

概述我有一个问题,当android:hardwareAccelerated设置为清单文件中的false时,最新的SamsungGalaxy系列才出现据我所知(我自己尝试过),它会在GalaxyS9,J6和Note8上发生,例如在GalaxyS8上不会发生.其他电话似乎根本不受影响.问题是我得到了一个GLSurfaceView,它什么也不显示(黑屏),

我有一个问题,当android:harDWareAccelerated设置为清单文件中的false时,最新的Samsung galaxy系列才出现

据我所知(我自己尝试过),它会在galaxy S9,J6和Note 8上发生,例如在galaxy S8上不会发生.其他电话似乎根本不受影响.

问题是我得到了一个GLSurfaceVIEw,它什么也不显示(黑屏),但是如果我在活动之间进行切换,它将再次开始工作,我想是因为它可以无错误地更新VIEw.

这是我发现的可疑日志行

01-13 14:39:47.813 25013 25080 E libEGL  : eglCreatewindowsurface: native_window_API_connect (win=0xc166b808) Failed (0xffffffed) (already connected to another API?)01-13 14:39:47.813 25013 25080 E libEGL  : eglCreatewindowsurface:679 error 3003 (EGL_BAD_ALLOC)

这些是我的代码的关键部分:

GLSurf glsurf;public voID onPause() {    super.onPause();    // stop    if (glsurf != null) {        glsurf.onPause();    }}@OverrIDepublic voID onResume() {    super.onResume();    if (glsurf != null)        glsurf.onResume();}public class GLSurf extends GLSurfaceVIEw {    public GLSurf(Context context) {        super(context);        /* Create an OpenGL ES 2.0 context. */        setEGLContextClIEntVersion(2);        setEGLConfigChooser(8, 8, 8, 8, 16, 0);        // Set the Renderer for drawing on the GLSurfaceVIEw        mRenderer = new glrenderer(context);        setRenderer(mRenderer);        setRenderMode(GLSurfaceVIEw.RENDERMODE_CONTINUOUSLY);    }}public class glrenderer implements Renderer {    glrenderer(Context c){        // does nothing    }    @OverrIDe    public voID onDrawFrame(GL10 unused) {        // i've copIEd it but it's not even reached        // call jni function updating the single texture filling the screen        nativeglrender();        // Draw the triangles        GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length,                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);    }    @OverrIDe    public voID onSurfaceChanged(GL10 gl, int wIDth, int height) {        // We need to kNow the current wIDth and height.        mScreenWIDth = wIDth;        mScreenHeight = height;        // Redo the VIEwport.        GLES20.glVIEwport(0, 0, (int)mScreenWIDth, (int)mScreenHeight);    }    @OverrIDe    public voID onSurfaceCreated(GL10 gl, EGLConfig config) {        // Set the clear color to black        GLES20.glClearcolor(0.0f, 0.0f, 0.0f, 1);    }}

更多信息:

EGL_BAD_ALLOC总是在具有有意义(至少我认为)日志的事件序列之后发生

onCreateonResumeonPauseGLSurfaceVIEw: Warning, !readyToDraw() but waiting for draw finished! Early reporting draw finished.onResume libEGL  : eglCreatewindowsurface: native_window_API_connect (win=0xc166b808) Failed (0xffffffed) (already connected to another API?)libEGL  : eglCreatewindowsurface:679 error 3003 (EGL_BAD_ALLOC)onPauseonStoponDestroyonCreate onResumeonSurfaceCreated        : NulL == surf->write_back_color_buffer        : NulL == surf->write_back_color_bufferGLThread: eglSwapBuffers Failed: EGL_BAD_SURFACE... black screen ...

请注意,上述事件是在没有用户交互的情况下发生的,且发生时间为1-2秒.关于发生了什么的任何想法?

为了完成信息的处理,以下是可正常使用的电话的顺序(例如,我的nexus 6)

onCreateonResumeonSurfaceCreated... working screen

编辑1月16日:

有关此问题的新信息:

>首次启动应用程序时,它可以运行
>从不尝试下一次尝试
>如果放在后台并还原,则可以使用
>如果我将androID:harDWareAccelerated设置为true,则错误永远不会发生(但由于其他原因我无法将其打开)

编辑1月18日

>我忘了提到,仅当androID:harDWareAccelerated设置为false时,该问题才会出现

我也发现了错误的原因

不知道为什么,但我只是更改了这部分代码

@OverrIDepublic voID onAttachedToWindow() {    super.onAttachedToWindow();    getwindow().setFormat(PixelFormat.RGB_565);}

有了这个

@OverrIDepublic voID onAttachedToWindow() {    super.onAttachedToWindow();}

一切顺利.三星驱动程序中的错误?也许…

我希望这对某人有用

解决方法:

eglCreatewindowsurface: native_window_API_connect Failed Any IDea
about what’s going on?

从logcat角度看的问题

从eglApi.cpp开始的调用函数是:

/* * native_window_API_connect(..., int API) * connects an API to this window. only one API can be connected at a time. * Returns -EINVAL if for some reason the window cannot be connected, which * can happen if it's connected to some other API. */static inline int native_window_API_connect(        struct ANativeWindow* window, int API){    return window->perform(window, NATIVE_WINDOW_API_CONNECT, API);}

这是来自WindowSurface.java方法的windowsurface.recreate()的注释块,其中说:

/* * If the prevIoUs EGLSurface isn't fully destroyed, e.g. it's still current on a * context somewhere, the create call will fail with complaints from the Surface * about already being connected.*/

相关问题

来自Jitesh Dalsaniya的Opengls eglCreateWindowSurface GL Error EGL_BAD_ALLOC

I solved error GL Error EGL_BAD_ALLOC. This error occurs due to I am
not handling Renderer properly with activity life cycle.

Activity life-cycle

A GLSurfaceVIEw must be notifIEd when to pause and
resume rendering. GLSurfaceVIEw clIEnts are required to call onPause() when the activity stops and onResume() when the activity
starts. These calls allow GLSurfaceVIEw to pause and resume the
rendering thread, and also allow GLSurfaceVIEw to release and
recreate the OpenGL display.

EGL上下文丢失

There are situations where the EGL rendering context will be lost.
This typically happens when device wakes up after going to sleep. When
the EGL context is lost, all OpenGL resources (such as textures)
that are associated with that context will be automatically deleted.
In order to keep rendering correctly, a renderer must recreate any
lost resources that it still needs. The onSurfaceCreated(GL10,
EGLConfig) method is a convenIEnt place to do this.

Workaround-to-losing-the-opengl-context-when-android-pauses

因此,您的Activity的onPause()应该如下所示:

@OverrIDepublic voID onPause() {    glsurf.setVisibility(VIEw.GONE);    super.onPause();    ...}

然后,您不是从onResume()而是从onWindowFocusChanged()将GLSurfaceVIEw还原到层次结构中:

@OverrIDepublic voID onWindowFocusChanged(boolean hasFocus) {    super.onWindowFocusChanged(hasFocus);    if (hasFocus && glsurf.getVisibility() == VIEw.GONE) {         glsurf.setVisibility(VIEw.VISIBLE);    }    ...}

其他尝试

>您需要调试才能弄清楚为什么它不满意.
>尝试始终使用OpenglVIEw Visible,并在获得许可时使用startPrevIEw.隐形持有人对opengl无效,这可能会导致崩溃.
> Opengl版本不好?
>处理TextureVIEwGLActivity中的onSurfaceTextureSizeChanged吗?
> EGL_BAD_ALLOC和eglSwapBuffers失败:EGL_BAD_SURFACE是一个大提示…
>!readyToDraw()删除并重新创建Surface?

进一步

观察:

The error never happen if I put androID:harDWareAccelerated to true

HarDWare acceleration is enabled by default if your Target API level
is >=14, but can also be explicitly enabled (at the Application or Activity level).

文件连结

GLSurfaceView、GLSurfaceView.Renderer、hardware-acceleration

总结

以上是内存溢出为你收集整理的android-eglCreateWindowSurface:native_window_api_connect失败全部内容,希望文章能够帮你解决android-eglCreateWindowSurface:native_window_api_connect失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1094852.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存