diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-06-28 08:12:07 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-06-28 08:12:07 +0200 |
commit | 68e5a04f438fafd984ac0bf0424fa75294a8dc06 (patch) | |
tree | bc7bc3ec85629824a25184539a708ea226f747b3 /opentrack-logic/keybinding-worker.cpp | |
parent | 1fddde254bb0c9532304ccd7db91aa1b6df5c3bf (diff) |
logic/joystick: fix multiple bugs
- the enumerator and the handle list are now static; joysticks were
erroneously destructed during refresh
- setup dinput only once; creating LPDIRECTINPUT8 many times causes
Release() to invalidate all handles
- don't create joystick handles many times; same thing applies
- refresh joy list on failed acquire; usually joystick is unplugged at
that moment leading to endless stderr spam
- use a static mutex as to avoid dinput races
Issue: #315
Diffstat (limited to 'opentrack-logic/keybinding-worker.cpp')
-rw-r--r-- | opentrack-logic/keybinding-worker.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/opentrack-logic/keybinding-worker.cpp b/opentrack-logic/keybinding-worker.cpp index a0c7178c..eba026a5 100644 --- a/opentrack-logic/keybinding-worker.cpp +++ b/opentrack-logic/keybinding-worker.cpp @@ -55,7 +55,7 @@ KeybindingWorker::KeybindingWorker() : din = 0; return; } - + if (dinkeyboard->SetCooperativeLevel((HWND) fake_main_window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) { dinkeyboard->Release(); din->Release(); @@ -165,7 +165,7 @@ KeybindingWorker::fun* KeybindingWorker::_add_receiver(fun& receiver) QMutexLocker l(&mtx); receivers.push_back(std::unique_ptr<fun>(new fun(receiver))); fun* f = receivers[receivers.size() - 1].get(); - qDebug() << "add receiver" << (long) f; + //qDebug() << "add receiver" << (long) f; joy_ctx.refresh(); return f; } @@ -175,12 +175,15 @@ void KeybindingWorker::remove_receiver(KeybindingWorker::fun* pos) QMutexLocker l(&mtx); bool ok = false; - for (int i = receivers.size() - 1; i >= 0; i--) + using s = int; + + for (int i = s(receivers.size()) - 1; i >= 0; i--) { - if (receivers[i].get() == pos) + using u = unsigned; + if (receivers[u(i)].get() == pos) { ok = true; - qDebug() << "remove receiver" << (long) pos; + //qDebug() << "remove receiver" << (long) pos; receivers.erase(receivers.begin() + i); break; } |