From 7fed80d74cfbbf94d09622051056bd2e10d8de96 Mon Sep 17 00:00:00 2001 From: Norbyte Date: Fri, 29 Mar 2024 21:13:16 +0100 Subject: [PATCH] Fix possible freeze during startup after early thread suspend --- BG3Updater/Updater.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/BG3Updater/Updater.cpp b/BG3Updater/Updater.cpp index 396bbc2f..ff560cba 100644 --- a/BG3Updater/Updater.cpp +++ b/BG3Updater/Updater.cpp @@ -481,13 +481,27 @@ HRESULT UpdaterUI::UICallback(HWND hwnd, UINT uNotification, WPARAM wParam, LPAR return S_OK; } +volatile bool NeedsClientSuspend{ false }; + +DWORD WINAPI DelayedClientSuspenderThread(LPVOID param) +{ + Sleep(1000); + if (NeedsClientSuspend) { + DEBUG("Suspending client thread"); + gGameHelpers->SuspendClientThread(); + } + return 0; +} + DWORD WINAPI UpdaterThread(LPVOID param) { - gGameHelpers->SuspendClientThread(); gUpdater->InitConsole(); gUpdater->InitUI(); DEBUG("Launch loader"); + NeedsClientSuspend = true; + CreateThread(NULL, 0, &DelayedClientSuspenderThread, NULL, 0, NULL); gUpdater->Run(); + NeedsClientSuspend = false; gGameHelpers->ResumeClientThread(); DEBUG("Extender launcher thread exiting"); return 0;