From ed86f69c8522e0795a5d9cbafa0a15f97d40d520 Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Thu, 17 Jun 2021 19:15:35 +0300 Subject: [PATCH] Explicitly initialize COM library in main and opengl threads, hopefully fixing filedialog issues. --- src/win/win.c | 6 ++++++ src/win/win_opengl.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/win/win.c b/src/win/win.c index 1bff61fee..0854dac64 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -417,6 +417,9 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) SetCurrentProcessExplicitAppUserModelID(AppID); + /* Initialize the COM library for the main thread. */ + CoInitializeEx(NULL, COINIT_MULTITHREADED); + /* Check if Windows supports UTF-8 */ if (GetACP() == CP_UTF8) acp_utf8 = 1; @@ -465,6 +468,9 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) /* Handle our GUI. */ i = ui_init(nCmdShow); + /* Uninitialize COM before exit. */ + CoUninitialize(); + free(argbuf); free(argv); return(i); diff --git a/src/win/win_opengl.c b/src/win/win_opengl.c index 8a181a4c3..387c24c67 100644 --- a/src/win/win_opengl.c +++ b/src/win/win_opengl.c @@ -468,6 +468,9 @@ static void __stdcall opengl_debugmsg_callback(GLenum source, GLenum type, GLuin */ static void opengl_main(void* param) { + /* Initialize COM library for this thread before SDL does so. */ + CoInitializeEx(NULL, COINIT_MULTITHREADED); + SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); /* Is this actually doing anything...? */ @@ -788,6 +791,8 @@ static void opengl_main(void* param) SDL_DestroyWindow(window); window = NULL; + + CoUninitialize(); } static void opengl_blit(int x, int y, int y1, int y2, int w, int h)