From 3bef4a5da6df4dc87fa45b7e9d1b6cab74d3637a Mon Sep 17 00:00:00 2001 From: pionere Date: Sat, 22 Jan 2022 15:43:09 +0100 Subject: [PATCH] cleanup error-handling in SDL_egl.c - always set error message in SDL_EGL_ChooseConfig / SDL_EGL_CreateContext - assume SDL_EGL_DeleteContext does not alter the error message - sync generic error message of SDL_EGL_MakeCurrent with SDL_EGL_Get/SetSwapInterval - do not overwrite error message of SDL_EGL_ChooseConfig in WINRT_CreateWindow --- src/video/SDL_egl.c | 19 +++++-------------- src/video/winrt/SDL_winrtvideo.cpp | 5 ++--- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index e10cf7c70..c9fb476b0 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -909,8 +909,7 @@ SDL_EGL_ChooseConfig(_THIS) int ret; if (!_this->egl_data) { - /* The EGL library wasn't loaded, SDL_GetError() should have info */ - return -1; + return SDL_SetError("EGL not initialized"); } /* Try with EGL_CONFIG_CAVEAT set to EGL_NONE, to avoid any EGL_SLOW_CONFIG or EGL_NON_CONFORMANT_CONFIG */ @@ -943,7 +942,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES); if (!_this->egl_data) { - /* The EGL library wasn't loaded, SDL_GetError() should have info */ + SDL_SetError("EGL not initialized"); return NULL; } @@ -1044,16 +1043,8 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) _this->egl_data->egl_swapinterval = 0; if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) { - /* Save the SDL error set by SDL_EGL_MakeCurrent */ - char errorText[1024]; - SDL_strlcpy(errorText, SDL_GetError(), SDL_arraysize(errorText)); - - /* Delete the context, which may alter the value returned by SDL_GetError() */ + /* Delete the context */ SDL_EGL_DeleteContext(_this, egl_context); - - /* Restore the SDL error */ - SDL_SetError("%s", errorText); - return NULL; } @@ -1096,7 +1087,7 @@ SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context) EGLContext egl_context = (EGLContext) context; if (!_this->egl_data) { - return SDL_SetError("OpenGL not initialized"); + return SDL_SetError("EGL not initialized"); } if (!_this->egl_data->eglMakeCurrent) { @@ -1104,7 +1095,7 @@ SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context) /* Can't do the nothing there is to do? Probably trying to cleanup a failed startup, just return. */ return 0; } else { - return SDL_SetError("OpenGL not initialized"); /* something clearly went wrong somewhere. */ + return SDL_SetError("EGL not initialized"); /* something clearly went wrong somewhere. */ } } diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index 5b917dbb4..6ed5918e7 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -670,9 +670,8 @@ WINRT_CreateWindow(_THIS, SDL_Window * window) * be passed into eglCreateWindowSurface. */ if (SDL_EGL_ChooseConfig(_this) != 0) { - char buf[512]; - SDL_snprintf(buf, sizeof(buf), "SDL_EGL_ChooseConfig failed: %s", SDL_GetError()); - return SDL_SetError("%s", buf); + /* SDL_EGL_ChooseConfig failed, SDL_GetError() should have info */ + return -1; } if (video_data->winrtEglWindow) { /* ... is the 'old' version of ANGLE/WinRT being used? */