Skip to content

Commit

Permalink
Fix possible freeze during startup after early thread suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Mar 29, 2024
1 parent bb5f974 commit 7fed80d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion BG3Updater/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7fed80d

Please sign in to comment.