1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Fixed a potential deadlock in resetMouseHook

Fixes a sporadic deadlock when alt-tabbing in Star Trek: Armada with the
config overlay open.
This commit is contained in:
narzoul 2024-06-29 23:22:07 +02:00
parent ec686bfb69
commit a442239ac1
3 changed files with 40 additions and 25 deletions

View File

@ -20,6 +20,7 @@
namespace
{
const UINT WM_USER_EXECUTE = WM_USER;
const UINT WM_USER_EXECUTE_ASYNC = WM_USER + 1;
struct EnumWindowsArgs
{
@ -185,6 +186,12 @@ namespace
func();
return 0;
}
if (WM_USER_EXECUTE_ASYNC == uMsg)
{
auto func = reinterpret_cast<void(*)()>(lParam);
func();
return 0;
}
return CALL_ORIG_FUNC(DefWindowProc)(hwnd, uMsg, wParam, lParam);
}
@ -277,6 +284,11 @@ namespace Gdi
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
void executeAsyncFunc(void(*func)())
{
PostMessage(g_messageWindow, WM_USER_EXECUTE_ASYNC, 0, reinterpret_cast<LPARAM>(func));
}
void executeFunc(const std::function<void()>& func)
{
DWORD_PTR result = 0;

View File

@ -27,6 +27,7 @@ namespace Gdi
template <typename Func>
void execute(const Func& func) { executeFunc(std::cref(func)); }
void executeAsyncFunc(void(*func)());
void executeFunc(const std::function<void()>& func);
bool isGuiThreadWindow(HWND hwnd);

View File

@ -268,9 +268,7 @@ namespace
});
}
void resetMouseHook()
{
Gdi::GuiThread::execute([]()
void resetMouseHookFunc()
{
if (g_mouseHook)
{
@ -294,7 +292,11 @@ namespace
{
LOG_ONCE("ERROR: Failed to install low level mouse hook, error code: " << GetLastError());
}
});
}
void resetMouseHook()
{
Gdi::GuiThread::executeAsyncFunc(resetMouseHookFunc);
}
BOOL WINAPI setCursorPos(int X, int Y)