EGL crash on eglInitialize with COLIBRI IMX8X

Hello,

I am currently porting a software that use EGL under linux on the colibri IMX8X platform and there is a crash when I run the software.

I am not familiar with EGL / GLES software ( I am network programmer ) so I don’t know exactly how it works, but I was able to create a minimal code example that crashes.

Here is the code :

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include <EGL/egl.h>
#include <GLES2/gl2.h>

GC      gc;
Display *display;
int     screen;
Window  win, root;
unsigned long white_pixel, black_pixel;

main() {
  XInitThreads();
  if ((display = XOpenDisplay ("")) == NULL) {
    fprintf (stderr, "Can't open Display\n");
    exit (1);
  }
  gc = DefaultGC (display, screen);
  screen = DefaultScreen (display);
  root = RootWindow (display, screen);
  white_pixel = WhitePixel (display, screen);
  black_pixel = BlackPixel (display, screen);
  XSetBackground (display, gc, white_pixel);
  XSetForeground (display, gc, black_pixel);
  win = XCreateSimpleWindow (display, root,
               0, 0, 400, 300, 5, black_pixel, white_pixel);
  XSelectInput (display, win, ExposureMask);
  XStoreName (display, win, "test egl");
  XMapWindow (display, win);

  
  EGLDisplay egl_disp = eglGetDisplay((NativeDisplayType)display);
  EGLint major, minor;
  printf("avant initialize\n");
  eglInitialize(egl_disp, &major, &minor);
  printf("major : %d , minor : %d\n",major,minor);
  

  for (;;) {
    XEvent ev;
    XNextEvent (display, &ev);
    switch (ev.type) {
    case Expose :
      break;
    default :
      break;
    }
  }
}

I have set my environnement build like this :

. /opt/tdx-xwayland/5.2.0/environment-setup-aarch64-tdx-linux

And I have build the sample test like this ( ignore warnings, this is just a quick sample ):

$CC -o test test.c -lX11  -lXext  -lxcb  -lXau  -lpthread  -lm  -lEGL  -lGLESv2

If I comment the part with EGL… , it runs well and the window is created.
If I uncomment the part with EGL … it crashes when eglInitialize is called.

I have tested this code under my linux desktop ( debian 10 64 bits ), and it runs well , and the major/minor version displayed is : 1.4

The code I have to build is an old software written in X11 and with EGL extension after. I cannot rewrite it. Maybe the issue is that I want X11 + EGL on the IMX8X where the graphic layer is wayland and not xorg/x11 ?
Or maybe there is another way to initialize egl , or any restriction ?

Regards,

I have a more compact code :

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include <EGL/egl.h>
#include <GLES2/gl2.h>

Display *display;

int main() {
  if ((display = XOpenDisplay ("")) == NULL) {
    fprintf (stderr, "Can't open Display\n");
    exit (1);
  }
  EGLDisplay egl_disp = eglGetDisplay((NativeDisplayType)display);
  EGLint major, minor;
  eglInitialize(egl_disp, &major, &minor);
  printf("major : %d , minor : %d\n",major,minor);

  XCloseDisplay(display);
}

Just XOpenDisplay, and then eglInitialize, and it crashes ( works well on debian 10 )

another sample :

git clone https://gitlab.freedesktop.org/mesa/demos
cd demos/src/egl/opengles2/
. /opt/tdx-xwayland/5.2.0/environment-setup-aarch64-tdx-linux
$CC -o es2tri es2tri.c  -lX11   -lm  -lEGL  -lGLESv2

crash on colibri imx8x with tdx-reference-multimedia-image 5.2.0
runs correctly on debian 10 64 bits ( displays a window with a triangle )

all glmark2 software don’t work :

root@colibri-imx8x:/tmp# glmark2
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Error: GLX version >= 1.3 is required
Error: Error: Couldn't get GL visual config!
Error: main: Could not initialize canvas
root@colibri-imx8x:/tmp# glmark2-drm
EGL: Warning: No default display support on wayland
Error: Failed to bind api EGL_OPENGL_ES_API
Error: eglCreateContext() failed with error: 0x3005
Error: CanvasGeneric: Invalid EGL state
Error: main: Could not initialize canvas
Error: Failed to restore original CRTC: -13
root@colibri-imx8x:/tmp# glmark2-es2
[GL: Warning: No default display support on wayland
  1781.124930] audit: type=1701 audit(1615219321.761:11): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=835 comm="glmark2-es2" exe="/usr/bin/glmark2-es2" sig=11 res=1
Segmentation fault
root@colibri-imx8x:/tmp# glmark2-es2-drm
EGL: Warning: No default display support on wayland
=======================================================
    glmark2 2017.07
=======================================================
    OpenGL Information
    GL_VENDOR:     Vivante Corporation
    GL_RENDERER:   Vivante GC7000L
    GL_VERSION:    OpenGL ES 3.1 V6.4.3.p1.305572
=======================================================
[build] use-vbo=false:Error: Failed to set crtc: -13
Error: Failed to set crtc: -13
Error: Failed to set crtc: -13
^C
root@colibri-imx8x:/tmp# glmark2-wayland
EGL: Warning: No default display support on wayland
Error: Failed to bind api EGL_OPENGL_ES_API
Error: eglCreateContext() failed with error: 0x3005
Error: CanvasGeneric: Invalid EGL state
Error: main: Could not initialize canvas
root@colibri-imx8x:/tmp#

except glmark2-es2-wayland. This one works with some warning message :

root@colibri-imx8x:/tmp# glmark2-es2-wayland
EGL: Warning: No default display support on wayland
=======================================================
    glmark2 2017.07
=======================================================
    OpenGL Information
    GL_VENDOR:     Vivante Corporation
    GL_RENDERER:   Vivante GC7000L
    GL_VERSION:    OpenGL ES 3.1 V6.4.3.p1.305572
=======================================================
[build] use-vbo=false:

Maybe I have to see how glmark2-es2-wayland is initialized to do the same thing, but I don’t find the source code at this time :frowning:

Issue resolved by changing the code.

It is impossible to use egl with xorg/wayland wrapper, it crashes.

The only way is to write the window creation with wayland api ( wl_display_connect / wl_egl_createwindow / etc. )

Issue resolved.

Hello @f.mazur,

Thank you for your feedback.

Best Regards,
Janani