summaryrefslogtreecommitdiffhomepage
path: root/dinput/keybinding-worker.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-14 12:31:37 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-14 12:34:33 +0200
commitdb8ef6165c746b233cd9a61101ed32c4c14a426c (patch)
tree9880482ba20f32ab56360e3c0a2d02a586c460cc /dinput/keybinding-worker.cpp
parent2d7e8f1467a37b66a87c949ad266dc9b41c9a1b1 (diff)
dinput: fix dinput freeze
It was easiest to reproduce when a protocol failed to load. As usual, win32 debugging without MSVC++ is nearly useless.
Diffstat (limited to 'dinput/keybinding-worker.cpp')
-rw-r--r--dinput/keybinding-worker.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp
index 32bfc6f0..70914f92 100644
--- a/dinput/keybinding-worker.cpp
+++ b/dinput/keybinding-worker.cpp
@@ -35,33 +35,31 @@ KeybindingWorker::~KeybindingWorker()
}
}
-void KeybindingWorker::init()
+bool KeybindingWorker::init()
{
- din = dinput_handle::make_di();
-
if (!din)
{
qDebug() << "can't create dinput handle";
- return;
+ return false;
}
if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL) != DI_OK) {
qDebug() << "setup CreateDevice function failed!" << GetLastError();
- return;
+ return false;
}
if (dinkeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) {
qDebug() << "setup SetDataFormat function failed!" << GetLastError();
dinkeyboard->Release();
dinkeyboard = 0;
- return;
+ return false;
}
if (dinkeyboard->SetCooperativeLevel((HWND) fake_main_window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
dinkeyboard->Release();
dinkeyboard = 0;
qDebug() << "setup SetCooperativeLevel function failed!" << GetLastError();
- return;
+ return false;
}
if (dinkeyboard->Acquire() != DI_OK)
@@ -69,12 +67,16 @@ void KeybindingWorker::init()
dinkeyboard->Release();
dinkeyboard = 0;
qDebug() << "setup dinkeyboard Acquire failed!" << GetLastError();
- return;
+ return false;
}
+
+ return true;
}
-KeybindingWorker::KeybindingWorker() : should_quit(false)
+KeybindingWorker::KeybindingWorker() : dinkeyboard(nullptr), din(dinput_handle::make_di()), should_quit(false)
{
+ should_quit = !init();
+
start();
}
@@ -86,8 +88,6 @@ KeybindingWorker& KeybindingWorker::make()
void KeybindingWorker::run()
{
- init();
-
BYTE keystate[256] = {0};
BYTE old_keystate[256] = {0};