[KBM] Fix for handle leak (#11182)

This commit is contained in:
Enrico Giordani 2021-05-10 01:39:54 -07:00 committed by GitHub
parent 489ff37bf4
commit 617b7adb09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -50,6 +50,7 @@ KeyboardManager::KeyboardManager()
loadingSettings = false;
};
editorIsRunningEvent = CreateEvent(nullptr, true, false, KeyboardManagerConstants::EditorWindowEventName.c_str());
settingsEventWaiter = EventWaiter(KeyboardManagerConstants::SettingsEventName, changeSettingsCallback);
}
@ -126,8 +127,7 @@ intptr_t KeyboardManager::HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) n
}
// Suspend remapping if remap key/shortcut window is opened
auto h = CreateEvent(nullptr, true, false, KeyboardManagerConstants::EditorWindowEventName.c_str());
if (h != nullptr && WaitForSingleObject(h, 0) == WAIT_OBJECT_0)
if (editorIsRunningEvent != nullptr && WaitForSingleObject(editorIsRunningEvent, 0) == WAIT_OBJECT_0)
{
return 0;
}

View File

@ -9,7 +9,15 @@ class KeyboardManager
public:
// Constructor
KeyboardManager();
~KeyboardManager()
{
if (editorIsRunningEvent)
{
CloseHandle(editorIsRunningEvent);
}
}
void StartLowlevelKeyboardHook();
void StopLowlevelKeyboardHook();
@ -38,6 +46,8 @@ private:
std::atomic_bool loadingSettings = false;
HANDLE editorIsRunningEvent = nullptr;
// Hook procedure definition
static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);