Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.16: (Wayland without X) SDL_CreateWindow: failed to create an EGL window surface #4650

Closed
ghost opened this issue Aug 14, 2021 · 11 comments

Comments

@ghost
Copy link

ghost commented Aug 14, 2021

After commit 6a2af48ad73f8fc4e129ae7fc60589c82923224d

6a2af48ad73f8fc4e129ae7fc60589c82923224d is the first bad commit
commit 6a2af48ad73f8fc4e129ae7fc60589c82923224d
Author: Nicolas Caramelli <caramelli.devel@gmail.com>
Date:   Thu May 6 15:43:16 2021 +0200

    CMake: Generic check for desktop GL and EGL on Linux systems

 CMakeLists.txt        | 12 +++----
 cmake/sdlchecks.cmake | 98 +++++++++++++++++++++------------------------------
 2 files changed, 46 insertions(+), 64 deletions(-)

the Wayland build of SDL on a completely X-less system crashes on SDL_CreateWindow with failed to create an EGL window surface

example program:
(build and run with g++ $(pkg-config --libs --cflags sdl2) -o simple simple.cpp && ./simple)

#include <iostream>

#include <SDL2/SDL.h>


void sdl_exception(std::string operation) {
    std::cout << operation << ": " << SDL_GetError() << std::endl;
    std::exit(1);
}

int main() {
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        sdl_exception("SDL_Init");
    }

    auto window = SDL_CreateWindow(
            "Simple",
            SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED,
            1366,
            768,
            SDL_WINDOW_BORDERLESS | SDL_WINDOW_MAXIMIZED
    );
    if (window == nullptr) {
        sdl_exception("SDL_CreateWindow");
    }

    auto renderer = SDL_CreateRenderer(
            window,
            -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
    );
    if (renderer == nullptr) {
        sdl_exception("SDL_CreateRenderer");
    }

    auto running = true;

    while (running) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_KEYDOWN and event.key.keysym.sym == SDLK_ESCAPE) {
                running = false;
            }
        }
        if (SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0) < 0) {
            sdl_exception("SDL_SetRenderDrawColor");
        }
        if (SDL_RenderClear(renderer) < 0) {
            sdl_exception("SDL_RenderClear");
        }
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

On the previous commits, including previous releases, the code works.

And this is how SDL is being built:

pkgname=sdl2
pkgver=2.0.14+
vcs=git
gittag=6a2af48ad73f8fc4e129ae7fc60589c82923224d
relmon_id=4779

build() {
    ./autogen.sh
    cmake \
        -Bbuild \
        -GNinja \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DSDL_STATIC=OFF \
        -DSDL_DLOPEN=ON \
        -DARTS=OFF \
        -DESD=OFF \
        -DNAS=OFF \
        -DALSA=ON \
        -DVIDEO_WAYLAND=ON \
        -DVIDEO_X11=OFF \
        -DPULSEAUDIO_SHARED=ON \
        -DVIDEO_WAYLAND=ON \
        -DRPATH=OFF \
        -DCLOCK_GETTIME=ON \
        -DJACK_SHARED=ON
    ninja -C build
}

package() {
    DESTDIR=${pkgdir} ninja -C build install
    if [ -d ${pkgdir}/usr/lib64 ]; then
        mv ${pkgdir}/usr/lib{64,}
    fi
}
@flibitijibibo
Copy link
Collaborator

CC @caramelli, I believe this commit was specifically to allow X-less Wayland support.

@HurricanePootis
Copy link

HurricanePootis commented Aug 14, 2021

Do you have any X libraries in stalled on your system, or you running 100% with nothing X related installed? I am saying this because SDL2 is still linked to X libraries even if you are using Wayland.

Also, your sample program launched for me on KDE Wayland, which does requires X libraries even on Wayland.

@ghost
Copy link
Author

ghost commented Aug 14, 2021

I do not have X libraries in my system and SDL 2.0.14 builds and works without linking to them. Here is a full list of packages in my system:
https://github.com/alekseyrybalkin/packages/blob/main/buildorder

@ghost
Copy link
Author

ghost commented Aug 14, 2021

sdl2.build.log
Here is full build log

@ghost
Copy link
Author

ghost commented Aug 14, 2021

sdl2.build.2.0.16.log
And here is the build log for 2.0.16 on the same system. The interesting difference is:

< -- Performing Test HAVE_VIDEO_OPENGL
< -- Performing Test HAVE_VIDEO_OPENGL - Failed
> -- Performing Test HAVE_VIDEO_OPENGL_GLX
> -- Performing Test HAVE_VIDEO_OPENGL_GLX - Failed
> -- Performing Test HAVE_VIDEO_OPENGL
> -- Performing Test HAVE_VIDEO_OPENGL - Success

@caramelli
Copy link
Contributor

Before the commit 6a2af48, SDL2 was built for Wayland without OpenGL support on your system.
This commit is useful for enabling desktop GL on a pure Wayland system, but it requires having a working EGL / OpenGL implementation for the Wayland platform, which does not appear to be the case here (failure of your example).
You can therefore build SDL2 without OpenGL support as is the case with version 2.0.14 of your system by setting -DVIDEO_OPENGL=OFF -DVIDEO_OPENGLES=OFF when running cmake

@ghost
Copy link
Author

ghost commented Aug 15, 2021

Thanks! DVIDEO_OPENGL=OFF -DVIDEO_OPENGLES=ON did it for me (notice the ON for opengles).

The thing is, I do have a working EGL via mesa, but do not have GLX. So version 2.0.14, without these flags does detect this:

-- Performing Test HAVE_VIDEO_OPENGL
-- Performing Test HAVE_VIDEO_OPENGL - Failed
-- Checking for module 'egl'
--   Found egl, version 21.2.0
-- Performing Test HAVE_VIDEO_OPENGL_EGL
-- Performing Test HAVE_VIDEO_OPENGL_EGL - Success
-- Performing Test HAVE_VIDEO_OPENGLES_V1
-- Performing Test HAVE_VIDEO_OPENGLES_V1 - Failed
-- Performing Test HAVE_VIDEO_OPENGLES_V2
-- Performing Test HAVE_VIDEO_OPENGLES_V2 - Success
...
--   VIDEO_OPENGL           (Wanted: ON): OFF
--   VIDEO_OPENGLES         (Wanted: ON): ON

Notice that VIDEO_OPENGL in the end is off, but VIDEO_OPENGLES is on, which is correct for my system.

2.0.16, on the other hand does this:

-- Checking for module 'egl'
--   Found egl, version 21.2.0
-- Performing Test HAVE_VIDEO_OPENGL_EGL
-- Performing Test HAVE_VIDEO_OPENGL_EGL - Success
-- Checking for modules 'libdrm;gbm;egl'
--   Found libdrm, version 2.4.107
--   Found gbm, version 21.2.0
--   Found egl, version 21.2.0
-- dynamic libdrm -> libdrm.so.2
-- dynamic libgbm -> libgbm.so.1
-- Performing Test HAVE_VIDEO_OPENGL_GLX
-- Performing Test HAVE_VIDEO_OPENGL_GLX - Failed
-- Performing Test HAVE_VIDEO_OPENGL
-- Performing Test HAVE_VIDEO_OPENGL - Success
-- Performing Test HAVE_VIDEO_OPENGLES_V1
-- Performing Test HAVE_VIDEO_OPENGLES_V1 - Failed
-- Performing Test HAVE_VIDEO_OPENGLES_V2
-- Performing Test HAVE_VIDEO_OPENGLES_V2 - Success
...
--   VIDEO_OPENGL           (Wanted: ON): ON
--   VIDEO_OPENGLES         (Wanted: ON): ON

So it sets VIDEO_OPENGL incorrectly to on. So there is a bug with the autodetection.

@ghost
Copy link
Author

ghost commented Aug 15, 2021

I dug a little bit more and now I see that I do have in my system both gl.h and glext.h, but not glx.h, so the new check for VIDEO_OPENGL now succeeds. Is it enough to check only for these two to detect VIDEO_OPENGL? I don't know enough to answer. Is it more correct to say that my system is kind of "lying" about its capabilities or is the checking code too simple?

@ghost
Copy link
Author

ghost commented Aug 15, 2021

Both headers were installed by mesa, which was built for platform wayland with egl enabled and glx disabled, with this configuration:

    mkdir build
    meson --prefix=/usr \
        -D b_lto=false \
        -D b_ndebug=true \
        -D platforms=wayland \
        -D dri-drivers='i965' \
        -D gallium-drivers='swrast,iris' \
        -D vulkan-drivers='' \
        -D swr-arches=avx,avx2 \
        -D dri3=enabled \
        -D egl=enabled \
        -D gbm=enabled \
        -D gles1=disabled \
        -D gles2=enabled \
        -D glx=disabled \
        -D llvm=false \
        -D osmesa=true \
        -D shared-glapi=enabled \
        -D valgrind=false \
        -D libunwind=false \
        -D zstd=disabled \
        -D microsoft-clc=disabled \
        . build
    ninja -C build

@caramelli
Copy link
Contributor

Checking for glx.h does not make sense on a pure Wayland system (because it is based on EGL).
Using OpenGL ES on your system looks good, but desktop GL does not, so it would probably be best not to install the gl.h and glext.h headers on your system.

@ghost
Copy link
Author

ghost commented Aug 15, 2021

Perfect. Thanks for clarification!

@ghost ghost closed this as completed Aug 15, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants