diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-14 12:31:37 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-14 12:34:33 +0200 |
commit | db8ef6165c746b233cd9a61101ed32c4c14a426c (patch) | |
tree | 9880482ba20f32ab56360e3c0a2d02a586c460cc /dinput | |
parent | 2d7e8f1467a37b66a87c949ad266dc9b41c9a1b1 (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')
-rw-r--r-- | dinput/keybinding-worker.cpp | 22 | ||||
-rw-r--r-- | dinput/keybinding-worker.hpp | 2 | ||||
-rw-r--r-- | dinput/win32-joystick.cpp | 4 |
3 files changed, 14 insertions, 14 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}; diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp index 39b850e0..c2d571f8 100644 --- a/dinput/keybinding-worker.hpp +++ b/dinput/keybinding-worker.hpp @@ -51,7 +51,7 @@ private: volatile bool should_quit; void run() override; - void init(); + bool init(); KeybindingWorker(); static KeybindingWorker& make(); diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp index 9502bcd2..f0673309 100644 --- a/dinput/win32-joystick.cpp +++ b/dinput/win32-joystick.cpp @@ -346,13 +346,13 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumObjectsCallback(const DIDEVICEOBJEC win32_joy_ctx::joy::joy(LPDIRECTINPUTDEVICE8 handle, const QString &guid, const QString &name) : joy_handle(handle), guid(guid), name(name) { - qDebug() << "make joy" << guid << name << joy_handle; + //qDebug() << "make joy" << guid << name << joy_handle; std::memset(pressed, 0, sizeof(pressed)); } win32_joy_ctx::joy::~joy() { - qDebug() << "nix joy" << guid; + //qDebug() << "nix joy" << guid; release(); } |