App-Reinitialization fails with EGL_BAD_MATCH

1,037 views
Skip to first unread message

hellho...@web.de

unread,
Jun 11, 2013, 8:12:48 AM6/11/13
to andro...@googlegroups.com
I got my simple application running using NDK r8e with latest ADT version. Now I try to implement the Android specific application states.

When I suspend my application (on APP_CMD_TERM_WINDOW) I destroy my active Window surface and release the actual context
(the references to native objects, config, context and display are still hold by my wrapper objects) :

    if(m_support->getDisplay()!= EGL_NO_DISPLAY){   
        eglMakeCurrent(m_support->getDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        LOGI("Context released");
    }

    if(m_surface != EGL_NO_SURFACE)
    {
        eglDestroySurface(m_support->getDisplay(), m_surface);   
        brEGLSupport::checkForEGLError("[brEGLWindow]::destroyWindowSurface: " ,
                                       "[eglDestroySurface]: Could not destroy EGL surface!",
                                       true);
      
        m_surface = EGL_NO_SURFACE;  
        LOGI("Surface destroyed");                             
    }

This works fine. on reinitialization (on APP_CMD_INIT_WINDOW) I try to recreate the surface and finally
make the context current:

    brCore::brAssert<brCore::brIllegalStateException>(m_support.get(),
    "[brEGLWindow]::createWindowSurface: The brEGLSupport is invalid!");
   
    brCore::brAssert<brCore::brIllegalStateException>(m_config,
    "[brEGLWindow]::createWindowSurface: The EGL config is invalid!");

    m_surface = eglCreateWindowSurface(m_support->getDisplay(), m_config, m_nativeWindow, NULL);
    brEGLSupport::checkForEGLError("[brEGLWindow]::createWindowSurface: " ,
                                   "[eglCreateWindowSurface]: Could not initialize EGL surface!",
                                   true);
  
    LOGI("Surface created");   

    eglMakeCurrent(m_support->getDisplay(), m_surface, m_surface, m_context);

At this point the eglMakeCurrent call fails with EGL_BAD_MATCH error:

06-11 11:42:30.212: E/EGL_emulation(5671): tid 5693: eglMakeCurrent(922): error 0x3009 (EGL_BAD_MATCH)
06-11 11:42:30.212: E/libEGL(5671): eglMakeCurrent:593 error 3009 (EGL_BAD_MATCH)
06-11 11:42:30.262: A/libc(5671): @@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x4c1b9edc
06-11 11:42:30.262: A/libc(5671): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 5693 (com.binrev)

Google says it may be possible that my config is different, but it's the same I used
before on main application start without any issue based on this attribute settings:

       int attribs[] = {
            EGL_LEVEL, 0,
            EGL_DEPTH_SIZE, 16,
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_BLUE_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_RED_SIZE, 8,
            EGL_NONE,
            EGL_RENDERABLE_TYPE,
            EGL_OPENGL_ES2_BIT
        };

 Any Idea what could be going wrong?


a1

unread,
Jun 12, 2013, 3:47:58 AM6/12/13
to andro...@googlegroups.com
First of all you really do not have to tear down context, releasing surface is enough. But what's more important I'd say that this part of error report:

@@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x4c1b9edc
06-11 11:42:30.262: A/libc(5671): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 5693 (com.binrev)

is really worrisome, I'd say you are using released element (maybe display or context).

--
Bart

hellho...@web.de

unread,
Jun 13, 2013, 5:18:04 AM6/13/13
to andro...@googlegroups.com

First of all you really do not have to tear down context, releasing surface is enough.

Hmm, this is strange. If I do not release my context before I try to set up a new surface, The application crashes with the following
info:

06-13 08:48:54.195: I/brCameraSample(907): brEGLWindow: Try to create surface
06-13 08:48:54.200: E/libEGL(907): EGLNativeWindowType 0x2a1a8ba0 already connected to another API
06-13 08:48:54.200: E/libEGL(907): eglCreateWindowSurface:298 error 300b (EGL_BAD_NATIVE_WINDOW)
06-13 08:48:54.252: A/libc(907): @@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x4c1cdedc
06-13 08:48:54.252: A/libc(907): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 920 (com.binrev)
06-13 08:48:56.173: E/Trace(945): error opening trace file: No such file or directory (2)

If I release the context, the application fails at same point with nullpointer exception without detail informations:

06-13 09:09:43.601: I/brCameraSample(1005): brEGLWindow: Try to create surface
06-13 09:09:43.601: A/libc(1005): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1018 (com.binrev)

I've no idea where this nullpointer comes from. My context and my display and native window are not null ...

 

a1

unread,
Jun 13, 2013, 8:26:13 AM6/13/13
to andro...@googlegroups.com


W dniu czwartek, 13 czerwca 2013 11:18:04 UTC+2 użytkownik Hellho...@web.de napisał:

First of all you really do not have to tear down context, releasing surface is enough.

Hmm, this is strange. If I do not release my context before I try to set up a new surface, The application crashes with the following
info:

06-13 08:48:54.195: I/brCameraSample(907): brEGLWindow: Try to create surface
06-13 08:48:54.200: E/libEGL(907): EGLNativeWindowType 0x2a1a8ba0 already connected to another API
06-13 08:48:54.200: E/libEGL(907): eglCreateWindowSurface:298 error 300b (EGL_BAD_NATIVE_WINDOW)
06-13 08:48:54.252: A/libc(907): @@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x4c1cdedc
06-13 08:48:54.252: A/libc(907): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 920 (com.binrev)
06-13 08:48:56.173: E/Trace(945): error opening trace file: No such file or directory (2)

If I release the context, the application fails at same point with nullpointer exception without detail informations:

06-13 09:09:43.601: I/brCameraSample(1005): brEGLWindow: Try to create surface
06-13 09:09:43.601: A/libc(1005): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1018 (com.binrev)

I've no idea where this nullpointer comes from. My context and my display and native window are not null ...

Without code it's a bit hard to debug but I'd check if you correctly release and reacreate context - maybe you are releasing context (or other EGL object) but not reseting it, and thus ending with released object?

--
Bart

hellho...@web.de

unread,
Jun 13, 2013, 2:45:00 PM6/13/13
to andro...@googlegroups.com
Hmm strange, I've run the same code on my other PC, with and without tear down of the surface. Anything is working fine without
any exception. Tomorrow I will check the other PC again with same version of ADT, NDK and MinGW ... Up to this point, thanks
for your help.

David Given

unread,
Jun 13, 2013, 4:30:50 PM6/13/13
to andro...@googlegroups.com
On 13/06/13 19:45, Hellho...@web.de wrote:
> Hmm strange, I've run the same code on my other PC, with and without
> tear down of the surface. Anything is working fine without
> any exception. Tomorrow I will check the other PC again with same
> version of ADT, NDK and MinGW ... Up to this point, thanks
> for your help.

On Android you do have to destroy the context --- the context, surface
etc are all reference counted and the EGL system won't shut down cleanly
unless you tidy up scrupulously. (If it doesn't shut down cleanly it
won't start up cleanly again.)

The main thing that comes to mind for me is that it's probably worth
double checking that you're using the new value of m_nativeWindow that's
given to you by APP_CMD_INIT_WINDOW. If you're not, that would explain
the heap corruption (because the window gets destroyed after
APP_CMD_TERM_WINDOW is called).

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────

│ "Home is where, when you have to go there, they have to take you in."
│ --- Cordelia Naismith (via Robert Frost)

hellho...@web.de

unread,
Jun 14, 2013, 3:40:42 AM6/14/13
to andro...@googlegroups.com
Thanks for the hint with the native window, I've checked it. This was not the problem,
I always set a new native_window reference on APP_CMD_INIT_WINDOW. Only the
native display and config object is reused.

As promised I've tested the build on my other PC with new ADT and NDK installation,
and now it also works. There must be an issue with the old installation ... Now its
working fine on both PC's, next step is to test it on my mobile phone and tablet.

Thanks for your help.

a1

unread,
Jun 14, 2013, 3:43:05 AM6/14/13
to andro...@googlegroups.com

On Android you do have to destroy the context --- the context, surface
etc are all reference counted and the EGL system won't shut down cleanly
unless you tidy up scrupulously. (If it doesn't shut down cleanly it
won't start up cleanly again.)
Hold your horses there :) of course that you should dispose unused resources but you do not have to (and actually you shouldn't) destroy entire context when window is destroyed - that way you do not have to reload all you resource when app is paused.

--
Bart
 
Reply all
Reply to author
Forward
0 new messages