Fixed bug 3702 - Clear error messages of SDL_LoadObject for optional libraries
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Aug 2017 10:21:19 -0700
changeset 11219f94279990934
parent 11218 0060bcf673e8
child 11220 54ea94875b88
Fixed bug 3702 - Clear error messages of SDL_LoadObject for optional libraries

Simon Hug

Some code in SDL loads libraries with SDL_LoadObject to get more information or use newer APIs. SDL_LoadObject may fail, set an error message and SDL will continue with some fallback code. Since SDL will overwrite the error or exit the function with a return value that indicates success, the error form SDL_LoadObject for the optional stuff might as well be cleared right away.
src/audio/SDL_audio.c
src/video/SDL_egl.c
src/video/windows/SDL_windowskeyboard.c
src/video/windows/SDL_windowsvideo.c
     1.1 --- a/src/audio/SDL_audio.c	Fri Aug 11 10:18:45 2017 -0700
     1.2 +++ b/src/audio/SDL_audio.c	Fri Aug 11 10:21:19 2017 -0700
     1.3 @@ -150,6 +150,7 @@
     1.4      SDL_assert(SRC_lib == NULL);
     1.5      SRC_lib = SDL_LoadObject(SDL_LIBSAMPLERATE_DYNAMIC);
     1.6      if (!SRC_lib) {
     1.7 +        SDL_ClearError();
     1.8          return SDL_FALSE;
     1.9      }
    1.10  
     2.1 --- a/src/video/SDL_egl.c	Fri Aug 11 10:18:45 2017 -0700
     2.2 +++ b/src/video/SDL_egl.c	Fri Aug 11 10:21:19 2017 -0700
     2.3 @@ -269,7 +269,9 @@
     2.4          }
     2.5      }
     2.6      if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
     2.7 -        SDL_LoadObject(d3dcompiler);
     2.8 +        if (SDL_LoadObject(d3dcompiler) == NULL) {
     2.9 +            SDL_ClearError();
    2.10 +        }
    2.11      }
    2.12  #endif
    2.13  
     3.1 --- a/src/video/windows/SDL_windowskeyboard.c	Fri Aug 11 10:18:45 2017 -0700
     3.2 +++ b/src/video/windows/SDL_windowskeyboard.c	Fri Aug 11 10:21:19 2017 -0700
     3.3 @@ -351,6 +351,7 @@
     3.4      videodata->ime_himm32 = SDL_LoadObject("imm32.dll");
     3.5      if (!videodata->ime_himm32) {
     3.6          videodata->ime_available = SDL_FALSE;
     3.7 +        SDL_ClearError();
     3.8          return;
     3.9      }
    3.10      videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC");
     4.1 --- a/src/video/windows/SDL_windowsvideo.c	Fri Aug 11 10:18:45 2017 -0700
     4.2 +++ b/src/video/windows/SDL_windowsvideo.c	Fri Aug 11 10:21:19 2017 -0700
     4.3 @@ -113,11 +113,15 @@
     4.4          data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
     4.5          data->GetTouchInputInfo = (BOOL (WINAPI *)(HTOUCHINPUT, UINT, PTOUCHINPUT, int)) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
     4.6          data->RegisterTouchWindow = (BOOL (WINAPI *)(HWND, ULONG)) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
     4.7 +    } else {
     4.8 +        SDL_ClearError();
     4.9      }
    4.10  
    4.11      data->shcoreDLL = SDL_LoadObject("SHCORE.DLL");
    4.12      if (data->shcoreDLL) {
    4.13          data->GetDpiForMonitor = (HRESULT (WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *)) SDL_LoadFunction(data->shcoreDLL, "GetDpiForMonitor");
    4.14 +    } else {
    4.15 +        SDL_ClearError();
    4.16      }
    4.17  
    4.18      /* Set the function pointers */