summaryrefslogtreecommitdiffhomepage
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
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.
-rw-r--r--dinput/keybinding-worker.cpp22
-rw-r--r--dinput/keybinding-worker.hpp2
-rw-r--r--dinput/win32-joystick.cpp4
-rw-r--r--logic/shortcuts.h2
4 files changed, 15 insertions, 15 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();
}
diff --git a/logic/shortcuts.h b/logic/shortcuts.h
index d5dfd394..c81b01f6 100644
--- a/logic/shortcuts.h
+++ b/logic/shortcuts.h
@@ -30,7 +30,7 @@
using namespace options;
-struct OPENTRACK_LOGIC_EXPORT Shortcuts : public QObject
+struct OPENTRACK_LOGIC_EXPORT Shortcuts final : public QObject
{
Q_OBJECT