eglCreateWindowSurface crashes my app

r0neko

New Member
OP
Newbie
Joined
Jan 28, 2024
Messages
2
Trophies
0
Age
20
XP
18
Country
Romania
Hello everyone! I'm trying to port one of my game engines that I've working on to the Switch platform and I'm using devkitPRO as my toolchain.

I've had issues with getting their CMake toolchain to work 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; this is a different issue and not the main topic)

I've been looking around the devkitPRO forum for similar issues, but I couldn't find anything, and also my thread got rejected for some reason, and that's why I decided to try my shots on other forums as well.

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, requiring a restart.

If I run it inside an emulator (yuzu), it crashes the emulator entirely; 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. I think the backtrace got corrupted or something.

This is how my crashes look like:
1706439626531.png


The snippet of code I'm using is the following:
Code:
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 (it's my first time doing homebrew), so if possible, can I get some advice on how I can approach this issue and debug it properly?
I did some limited debugging using gdb in the emulator (yuzu), 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 properly, so I'm not sure if it's an issue because I'm linking the main game application with my engine library.

If you need any more information on how I'm trying to achieve things in my engine in order to understand together what I'm doing wrong, let me know.

Also, I don't know if this is the right zone to post this, so please let me know if I used the wrong forum for my issue.

Cheers!
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,280
Trophies
3
XP
12,046
Country
Poland
0xF59 = LibnxError_AlreadyInitialized

Which means this function tries to initialize something you have unnecesarily initialized earlier. Without following backtrace you can have hard time to figure that out if you have no idea what can be an issue, so GDB may be necessary to fix this.

And use Application mode if you don't want to crash whole system each time.
 
Last edited by masagrator,
  • Like
Reactions: r0neko

r0neko

New Member
OP
Newbie
Joined
Jan 28, 2024
Messages
2
Trophies
0
Age
20
XP
18
Country
Romania
0xF59 = LibnxError_AlreadyInitialized

Which means this function tries to initialize something you have unnecesarily initialized earlier. Without following backtrace you can have hard time to figure that out if you have no idea what can be an issue, so GDB may be necessary to fix this.

And use Application mode if you don't want to crash whole system each time.
Thanks for the answer. I tried to get gdbstub running but when it crashes, I can't get a backtrace because the connection gets cut.

It's strange, because I don't think it something related to nwindowGetDefault(), because if I call that function elsewhere it returns a valid handle just fine. So it surely has to be something inside the MESA implementation for the Switch.

Btw... not quite familiar with these stuff yet but by "application mode" you mean "applet mode" in the loader menu?
Post automatically merged:

Even if I managed to get the app working with a forwarder, it still crashes my system fully. I think that's what you meant by using application mode, right?
Post automatically merged:

I did some more digging through, and I think I found the culprit.

Somewhere in my platform code for the engine, I'm calling consoleInit(NULL); which guess what it did... it initialized the graphical renderer for the default window already!

So if you ever use consoleInit inside your app and you want to use EGL at the same time, it's not possible.

Now my engine works properly after removing the call to consoleInit! Thanks for the hint about what the error could be. It was quite helpful.
 
Last edited by r0neko,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: I did use a bot for Diablo III though but no ban there lol