[KBM] Fix for handle leak

This commit is contained in:
Enrico Giordani
2021-05-10 11:13:56 +02:00
parent d94919e21f
commit f51d42da37
2 changed files with 12 additions and 2 deletions

View File

@@ -51,6 +51,7 @@ KeyboardManager::KeyboardManager()
loadingSettings = false;
};
editorIsRunningEvent = CreateEvent(nullptr, true, false, KeyboardManagerConstants::EditorWindowEventName.c_str());
settingsEventWaiter = EventWaiter(KeyboardManagerConstants::SettingsEventName, changeSettingsCallback);
}
@@ -127,8 +128,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,6 +9,14 @@ public:
// Constructor
KeyboardManager();
~KeyboardManager()
{
if (editorIsRunningEvent)
{
CloseHandle(editorIsRunningEvent);
}
}
void StartLowlevelKeyboardHook();
void StopLowlevelKeyboardHook();
@@ -43,6 +51,8 @@ private:
// Load settings from the file.
void LoadSettings();
HANDLE editorIsRunningEvent = nullptr;
// Function called by the hook procedure to handle the events. This is the starting point function for remapping
intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept;
};