eglCreateWindowSurface crashes my app

Post Reply
User avatar
r0neko
Posts: 2
Joined: Sat Jan 27, 2024 3:48 pm
Contact:

eglCreateWindowSurface crashes my app

Post by r0neko » Sat Jan 27, 2024 4:12 pm

Hello! I'm trying to port one of my game engines that I've working on to the Switch platform.

I've had issues with getting the CMake toolchain working properly with my engine (I couldn't locate any documentation related to how to use it with CMake as most of the example projects use Makefiles; well this is a different issue)

I've been looking around the forum for similar issues, but I couldn't find anything, and that's why I decided to try my shots.

The main issue is that I'm trying to use EGL in order to fetch a proper context for the Switch window, but for some reason, whenever I call eglCreateWindowSurface inside my code, the app crashes, and I'm required to restart.

If I run it inside an emulator, it crashes the emulator entirely; but if I run it on proper, jailbroken hardware (it is the only way for me to develop and test homebrew games) I get a crash screen, which doesn't really provide useful information (https://imgur.com/a/7fSk1Io)

The snippet of code I'm using is the following:

Code: Select all

bool EGLGraphicsContext::init(windows::BaseAppWindowSPtr window) {
        const EGLint attribsCtx[] = {
                EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL_NONE
        };

        const EGLint attribs[] = {
                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
                EGL_BLUE_SIZE, 8,
                EGL_GREEN_SIZE, 8,
                EGL_RED_SIZE, 8,
                EGL_ALPHA_SIZE, 8,
                EGL_DEPTH_SIZE, 24,
                EGL_STENCIL_SIZE, 8,
                EGL_NONE
        };

        EGLConfig config;
        EGLint numConfigs;
        EGLint format;

        if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
            DEBUG_MSG("eglGetDisplay failed! %s\n", egl_get_error_string(eglGetError()).data())
            return false;
        }

        if (!eglInitialize(display, nullptr, nullptr)) {
            DEBUG_MSG("eglInitialize failed! %s\n", egl_get_error_string(eglGetError()).data())
            return false;
        }

        DEBUG_MSG("Loaded EGL %s.\n", eglQueryString(display, EGL_VERSION))

        if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
            DEBUG_MSG("eglChooseConfig failed! %s\n", egl_get_error_string(eglGetError()).data())
            return false;
        }

	// it crashes exactly here at this call for some reason
        surface = eglCreateWindowSurface(display, config, nwindowGetDefault(), nullptr);

        if (!surface) {
            DEBUG_MSG("eglCreateWindowSurface failed! %s\n",
                      egl_get_error_string(eglGetError()).data())
            return false;
        }

        DEBUG_MSG("eglCreateContext %lx\n", &eglCreateContext)

        if (!(context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribsCtx))) {
            DEBUG_MSG("eglCreateContext failed! %s\n", egl_get_error_string(eglGetError()).data())
            return false;
        }

        return true;
    }
I'm not really familiar with Console Development, so if possible, can I get some advice on how I can approach this issue and debug it?
I did some limited debugging, and I'm starting to suspect it may be something inside the mesa implementation for Switch or something with libnx.

The strange thing is that if I'm making a separate project in which I do the calls inside the application, the instance seems to get created, so I'm not sure if it's an issue because I'm linking the main game application with my engine library.

User avatar
r0neko
Posts: 2
Joined: Sat Jan 27, 2024 3:48 pm
Contact:

Re: eglCreateWindowSurface crashes my app

Post by r0neko » Sun Jan 28, 2024 6:04 pm

I managed to solve it by removing any calls to consoleInit();

consoleInit was initialising the renderer, and thus causing LibnxError_AlreadyInitialized when calling eglCreateWindowSurface because the renderer was already initialised for the default window.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests