From aa99b4a63ea0469f264733f0a5688a2258d91c72 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 28 Feb 2019 09:43:17 -0500 Subject: [PATCH] SDL_GL_LoadLibrary() has slightly different behavior between 1.2 and 2.0. --- src/SDL12_compat.c | 30 ++++++++++++++++++++++++++++++ src/SDL20_syms.h | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c index 3c61f3ee8..c62c5b60c 100644 --- a/src/SDL12_compat.c +++ b/src/SDL12_compat.c @@ -3054,6 +3054,36 @@ SDL_FreeYUVOverlay(SDL12_Overlay * overlay) FIXME("write me"); } +DECLSPEC int SDLCALL +SDL_GL_LoadLibrary(const char *libname) +{ + /* SDL 1.2 would unload the previous library if one was loaded. SDL2 + reports an error if one is already loaded, and sometimes loads it + internally for some video targets, so unloading it probably isn't safe. + There really isn't a good reason to be using anything other than the + system OpenGL in 2019, so we ignore the error in this case to match 1.2 + behavior, even if you were going to load a different library this time. + Oh well. */ + const int rc = SDL20_GL_LoadLibrary(libname); + if (rc == -1) { + const char *err = SDL20_GetError(); + if (SDL20_strcmp(err, "OpenGL library already loaded") == 0) { + return 0; + } + + /* reset the actual error. */ + char *dup = SDL_strdup(err); + if (!dup) { + SDL20_SetError("Out of memory"); + } else { + SDL20_SetError(dup); + SDL_free(dup); + } + } + return rc; +} + + DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL12_GLattr attr, int value) { diff --git a/src/SDL20_syms.h b/src/SDL20_syms.h index 7487cba11..fb36137f0 100644 --- a/src/SDL20_syms.h +++ b/src/SDL20_syms.h @@ -98,7 +98,7 @@ SDL20_SYM(int,GetColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return) SDL20_SYM(void,FreeSurface,(SDL_Surface *a),(a),) SDL20_SYM(SDL_Surface*,LoadBMP_RW,(SDL_RWops *a, int b),(a,b),return) SDL20_SYM(int,SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return) -SDL20_SYM_PASSTHROUGH(int,GL_LoadLibrary,(const char *a),(a),return) +SDL20_SYM(int,GL_LoadLibrary,(const char *a),(a),return) SDL20_SYM_PASSTHROUGH(void *,GL_GetProcAddress,(const char *a),(a),return) SDL20_SYM(int,GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return) SDL20_SYM(int,GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return)