Emulator crash after eglCreateWindowSurface()

Post Reply
Tenry
Posts: 14
Joined: Tue Jun 01, 2010 11:02 am
Location: Germany

Emulator crash after eglCreateWindowSurface()

Post by Tenry » Tue Oct 19, 2021 1:38 am

I am new to Switch homebrewing and I'm about to port my existing mini engine (originally written in C++ using SDL2 + OpenGL 4.3) to the Switch. It seems that I can not go with SDL2 + OpenGL (using my own OpenGL code), so I am following the existing examples using EGL + OpenGL. I am testing the builds *.nro file) in the yuzu and ryujinx emulators.

Depending on how far I got into my code, I am no longer able to do "consoleInit(nullptr);" + printing some debug or error messages. The exact point after which I am not able anymore is after I called eglCreateWindowSurface(). The yuzu emulator for example keeps haning on the emulator's "loading" screen. I'm unsure if anything until then went wrong, or if everything until then is just fine and something later doesn't work.

As for the EGL initialization part of my code, it looks like this:

Code: Select all

auto window = nwindowGetDefault();
nwindowSetDimensions(window, DISPLAY_WIDTH, DISPLAY_HEIGHT);

static const EGLint framebufferAttributeList[] = {
  EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
  EGL_RED_SIZE,     8,
  EGL_GREEN_SIZE,   8,
  EGL_BLUE_SIZE,    8,
  EGL_ALPHA_SIZE,   8,
  EGL_DEPTH_SIZE,   24,
  EGL_STENCIL_SIZE, 8,
  EGL_NONE
};

static const EGLint contextAttributeList[] = {
  EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
  EGL_CONTEXT_MAJOR_VERSION, 4,
  EGL_CONTEXT_MINOR_VERSION, 3,
  EGL_NONE
};

mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);

if(!mEglDisplay) {
  throw new std::runtime_error(eglErrorToString(eglGetError()));
}

if(eglInitialize(mEglDisplay, nullptr, nullptr) == EGL_FALSE) {
  throw new std::runtime_error(eglErrorToString(eglGetError()));
}

if(eglBindAPI(EGL_OPENGL_API) == EGL_FALSE) {
  throw new std::runtime_error(eglErrorToString(eglGetError()));
}

EGLConfig config;
EGLint numConfigs;
eglChooseConfig(mEglDisplay, framebufferAttributeList, &config, 1, &numConfigs);

if(numConfigs == 0) {
  throw new std::runtime_error(eglErrorToString(eglGetError()));
}

mEglSurface = eglCreateWindowSurface(mEglDisplay, config, window, nullptr); // <- emulator seems to hang here (?)

if(!mEglSurface) {
  throw new std::runtime_error(eglErrorToString(eglGetError()));
}

mEglContext = eglCreateContext(mEglDisplay, config, EGL_NO_CONTEXT, contextAttributeList);

if(!mEglContext) {
  throw new std::runtime_error(eglErrorToString(eglGetError()));
}

eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext);
I added a throw/catch expression in a different file, so in case of error my program will do "consoleInit(nullptr);" and print the error message, which works perfectly fine before "eglCreateWindowSurface" has been executed.

The only relevant code, I run before initializing EGL, is creating some small classes, doing nothing really in their constructors, and optionally "romfsInit()" (I also tried without romfs).

Does anyone have any clue what is possibly going wrong or how I can debug the Switch ROM better?

Tenry
Posts: 14
Joined: Tue Jun 01, 2010 11:02 am
Location: Germany

Re: Emulator crash after eglCreateWindowSurface()

Post by Tenry » Tue Oct 19, 2021 2:17 am

I found the issue in my GLSL shader code I'm compiling after EGL initialization.

The head of my GLSL shaders look like this:

Code: Select all

#version 430 core
#line 1 "vertex_shader.glsl"

...
I add "#line" statements into the shader code so in case of an error (on PC) I see the actual file and line number where that error originates from.

Unfortunately, the Switch (emulator) does not seem to like that. After removing the "#line" statements, my OpenGL code finally works perfectly fine in the emulator <3 (at least in yuzu; ryujinx gives me a black screen but at least it's not crashing anymore...)

That leads me to another question: is there a good way to debug my Switch / GLSL code (on an emulator) so I can spot that kind of errors more easily while I'll be adding more features into my GL code?

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests