Skip to content

Commit

Permalink
Fixed bug 3702 - Clear error messages of SDL_LoadObject for optional …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
slouken committed Aug 11, 2017
1 parent 6e1b11b commit 9630583
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/audio/SDL_audio.c
Expand Up @@ -150,6 +150,7 @@ LoadLibSampleRate(void)
SDL_assert(SRC_lib == NULL);
SRC_lib = SDL_LoadObject(SDL_LIBSAMPLERATE_DYNAMIC);
if (!SRC_lib) {
SDL_ClearError();
return SDL_FALSE;
}

Expand Down
4 changes: 3 additions & 1 deletion src/video/SDL_egl.c
Expand Up @@ -269,7 +269,9 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
}
}
if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
SDL_LoadObject(d3dcompiler);
if (SDL_LoadObject(d3dcompiler) == NULL) {
SDL_ClearError();
}
}
#endif

Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowskeyboard.c
Expand Up @@ -351,6 +351,7 @@ IME_Init(SDL_VideoData *videodata, HWND hwnd)
videodata->ime_himm32 = SDL_LoadObject("imm32.dll");
if (!videodata->ime_himm32) {
videodata->ime_available = SDL_FALSE;
SDL_ClearError();
return;
}
videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC");
Expand Down
4 changes: 4 additions & 0 deletions src/video/windows/SDL_windowsvideo.c
Expand Up @@ -113,11 +113,15 @@ WIN_CreateDevice(int devindex)
data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
data->GetTouchInputInfo = (BOOL (WINAPI *)(HTOUCHINPUT, UINT, PTOUCHINPUT, int)) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
data->RegisterTouchWindow = (BOOL (WINAPI *)(HWND, ULONG)) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
} else {
SDL_ClearError();
}

data->shcoreDLL = SDL_LoadObject("SHCORE.DLL");
if (data->shcoreDLL) {
data->GetDpiForMonitor = (HRESULT (WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *)) SDL_LoadFunction(data->shcoreDLL, "GetDpiForMonitor");
} else {
SDL_ClearError();
}

/* Set the function pointers */
Expand Down

0 comments on commit 9630583

Please sign in to comment.