Skip to content

Commit

Permalink
SDL: Try to continue if EGL init fails.
Browse files Browse the repository at this point in the history
Probably we should just stop using EGL on SDL2, but I'm not sure if
that's making things work for some users.  But if EGL init fails, try
to avoid a segfault and skip EGL.

Should help hrydgard#12474.
  • Loading branch information
unknownbrackets committed May 23, 2020
1 parent 0ff922c commit b46bf8e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions SDL/SDLGLGraphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static EGLSurface g_eglSurface = nullptr;
static EGLNativeDisplayType g_Display = nullptr;
static bool g_XDisplayOpen = false;
static EGLNativeWindowType g_Window = (EGLNativeWindowType)nullptr;
static bool useEGLSwap = false;

int CheckEGLErrors(const char *file, int line) {
EGLenum error;
Expand Down Expand Up @@ -328,7 +329,7 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std:
SetGLCoreContext(true);
#endif

window = SDL_CreateWindow("PPSSPP", x,y, pixel_xres, pixel_yres, mode);
window = SDL_CreateWindow("PPSSPP", x, y, pixel_xres, pixel_yres, mode);
if (!window) {
// Definitely don't shutdown here: we'll keep trying more GL versions.
fprintf(stderr, "SDL_CreateWindow failed for GL %d.%d: %s\n", ver.major, ver.minor, SDL_GetError());
Expand All @@ -353,7 +354,7 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SetGLCoreContext(false);

window = SDL_CreateWindow("PPSSPP", x,y, pixel_xres, pixel_yres, mode);
window = SDL_CreateWindow("PPSSPP", x, y, pixel_xres, pixel_yres, mode);
if (window == nullptr) {
NativeShutdown();
fprintf(stderr, "SDL_CreateWindow failed: %s\n", SDL_GetError());
Expand All @@ -376,11 +377,10 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std:
#ifdef USING_EGL
if (EGL_Open(window) != 0) {
printf("EGL_Open() failed\n");
return 1;
}
if (EGL_Init(window) != 0) {
} else if (EGL_Init(window) != 0) {
printf("EGL_Init() failed\n");
return 1;
} else {
useEGLSwap = true;
}
#endif

Expand Down Expand Up @@ -415,7 +415,10 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std:
assert(success);
renderManager_->SetSwapFunction([&]() {
#ifdef USING_EGL
eglSwapBuffers(g_eglDisplay, g_eglSurface);
if (useEGLSwap)
eglSwapBuffers(g_eglDisplay, g_eglSurface);
else
SDL_GL_SwapWindow(window_);
#else
SDL_GL_SwapWindow(window_);
#endif
Expand All @@ -433,7 +436,6 @@ void SDLGLGraphicsContext::ShutdownFromRenderThread() {

#ifdef USING_EGL
EGL_Close();
#else
SDL_GL_DeleteContext(glContext);
#endif
SDL_GL_DeleteContext(glContext);
}

0 comments on commit b46bf8e

Please sign in to comment.